Software Archive
Read-only legacy content
17060 Discussions

Win-API function CreateBitmapIndirect

Intel_C_Intel
Employee
318 Views
Hi folks,

I hope there is an expert on Win32 API who could help me with a frustrating problem.

I have developed a subroutine which prints a monochrome version of a rectangular section of the screen.

A test version of the code runs like this:

  1. Capture the screen using GETIMAGE.
  2. Convert the resulting 32-bit bitmap to a monochrome 1-bit bitmap, the DATA PART of which is stored in array IM_1 (i.e no header or RGB colors)
  3. Start using Win-32 routines


BM.bmType=0      
BM.bmWidth=ICOLTOT      
BM.bmHeight=IROWTOT   
BM.bmWidthBytes=NBYTE_ROW      
BM.bmPlanes=1      
BM.bmBitsPixel=1   
BM.bmBits=LOC(IM_1)   
hBM=CreateBitmapIndirect(BM)	 ! create win-32 bitmap structure  
hDCsc=CreateDC(DISPLAY,char(0),char(0),DV) ! Normal DC for screen  
hDCscComp=CreateCompatibleDC(hDCsc)	   ! memory screen  
IRES=SelectObject(hDCscComp,hBM)    ! select mono bitmap 
! As a test, copy mono image back to the real screen   
ires=BitBlt(hDCsc,100,100,ICOLTOT,IROWTOT,	 
+ hDCscComp,0,0,SRCCOPY) 



On Win NT 4.0 everything works perfectly in all cases.
On Win 95 or 98 it only works when the width of the selected screen rectangle is divisible by 32, i.e when no "zero padding" is required in constructing the IM_1 bitmap part.
When zero-padding is required, the image is totally "scrambled" showing that the created bitmap is "out of sync".

Any suggestions ???

Thanks
lars.engstrom@fysik.lu.se
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
318 Views
Well, the docs on BITMAP say, quote,

The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit, one-plane format. Each scan is a multiple of 32 bits.

Maybe it's not true for WinNT/2000, since GDI realizations btw. 9x and
NT do differ, however, it looks as if you'll have to redesign the code so that
BM.bmHeight is a multiply of 32. Well, it will require some conversion btw.
real image size (in general, not a multiply of 32) and 32-bit based memory representation, but I'm afraid you can't avoid that.

Jugoslav
0 Kudos
Intel_C_Intel
Employee
318 Views
Hi,Lars again.

I have "solved" the problem - although I don't understand the solution!!

The trick is to make the number of bytes per scan line (row) divisible by TWO (2). Then everyting works on all platforms.

However, every doc on bitmaps I have ever seen, incl SDK, states that you must pad to make the number of bytes divisible by FOUR (4) - word aligned.

I would still be happy if someone could help me understand this
0 Kudos
Reply