For Programmers: Free Programming Magazines  


Home > Archive > Compression > March 2006 > How to write monochrome .bmp bitmap?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to write monochrome .bmp bitmap?

2006-03-17, 7:55 am

Hello,
I am trying to wirte an application to write monochrome (1bit) bitmaps. But
I have a problem...
As I understand each line of pixels is Ceil(NumberOfPixels/8)+1 (#0- end of
line byte) in length, right?
But I did some tests and find out that sometimes I need to write one #0 byte
more on each line to get proper results.
Do you, by any chance, know why does it happen?

Regards,
Talthen



Dag-Erling Smørgrav

2006-03-17, 7:55 am

<talthen.z-serwera.o2@nospam.pl> writes:
> Hello, I am trying to wirte an application to write monochrome
> (1bit) bitmaps. But I have a problem... As I understand each line
> of pixels is Ceil(NumberOfPixels/8)+1 (#0- end of line byte) in
> length, right?


....rounded up to an even number, I believe.

DES
--
Dag-Erling Smørgrav - des@des.no

2006-03-17, 7:55 am


Uzytkownik "Dag-Erling "Smørgrav"" <des@des.no> napisal w wiadomosci
news:86d5gl1ceh.fsf@xps.des.no...
> <talthen.z-serwera.o2@nospam.pl> writes:
>



2006-03-17, 7:55 am

User "Dag-Erling "Smørgrav"" <des@des.no> wrote:
>
> ...rounded up to an even number, I believe.


Yeah, you are right. As in tests:

728x1 pixels=154 bytes
154bytes-62bytes(header)=(92bytes-1byte of "enter")*8=728 pixels

816x1 pixels=166 bytes
166bytes-62bytes(header)=(104bytes-2bytes of "enter")*8=816 pixels

Thanks,
Talthen


toby

2006-03-17, 6:55 pm

talthen.z-serwera.o2@nospam.pl wrote:
> User "Dag-Erling "Sm=F8rgrav"" <des@des.no> wrote:
>
> Yeah, you are right. As in tests:
>
> 728x1 pixels=3D154 bytes
> 154bytes-62bytes(header)=3D(92bytes-1byte of "enter")*8=3D728 pixels
>
> 816x1 pixels=3D166 bytes
> 166bytes-62bytes(header)=3D(104bytes-2bytes of "enter")*8=3D816 pixels


Actually MSDN docs say a multiple of four
(http://msdn.microsoft.com/library/d.../en-us/gdi/bit=
maps_4v1h.asp):

"The scan lines are DWORD aligned, except for RLE-compressed bitmaps.
They must be padded for scan line widths, in bytes, that are not evenly
divisible by four, except for RLE compressed bitmaps. For example, a
10- by 10-pixel 24-bpp bitmap will have two padding bytes at the end of
each scan line."

The following expression can be used
#define ROWBYTES(bits) ( ( ((bits)+31)/8 ) & -4 )

>=20
> Thanks,
> Talthen


2006-03-17, 6:55 pm

User "toby" <toby@telegraphics.com.au> wrote:
>Actually MSDN docs say a multiple of four
>(http://msdn.microsoft.com/library/d...itmaps_4v1h.asp):


>"The scan lines are DWORD aligned, except for RLE-compressed bitmaps.

Thanks for the info.

Regards,
Talthen


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com