RE: [GD-Windows] In memory bitmap to HBITMAP
Brought to you by:
vexxed72
From: Andrew G. <And...@ho...> - 2001-12-07 09:57:43
|
I've had this before, I can't remember what caused it but it turned out to be a "duh" error on my part. Code Guru (www.codeguru) is a great site for all sorts of GDI programming trickery. It's MFC based but the techniques are sound and it's not a great deal of pain to implment any of the samples in Win32. In this case http://www.codeguru.com/bitmap/bitmap_from_bmp.shtml. On another note, have you thought about using LoadImage() instead rather than doing it manually? Andrew Grant Hothouse Creations > -----Original Message----- > From: Brian Hook [mailto:bri...@py...] > Sent: 07 December 2001 02:04 > To: gam...@li... > Subject: [GD-Windows] In memory bitmap to HBITMAP > > > I'm struggling with something fairly basic -- I want to load a BMP out > of a compressed file, convert to an HBITMAP, then blit it into a DDraw > surface. I know how to do the first and last part, but the middle is > causing problems. Even worse, I'm not getting any errors. > > Loading the bitmap doesn't seem to be a problem. I load it > up and parse > and find the BITMAPFILEHEADER and BITMAPINFOHEADER no probs. I also > locate the raw bits no problem (and inspect with the debugger to make > sure I'm getting what I think I'm getting -- in this case, solid > magenta). Looks fine. > > The next step is to create a DC compatible with the desktop: > > HDC hDC = CreateCompatibleDC( NULL ); > > I then create a HBITMAP compatible with DC, and using the > bits I pulled: > > HBITMAP hbm; > > hbm = CreateDIBitmap( hDC, lpBMIH, CBM_INIT, lpBits, lpBMIH, > DIB_RGB_COLORS ); > > lpBMIH are simply pointers to the appropriate BITMAPINFOHEADER. They > have correct values in them. The bitmap is returned successfully. > > To verify things, I grab the bits out of the Bitmap to make sure > everything is cool: > > GetDIBits( hDC, hbm, 0, iHeight, tempbuffer, &bmi, DIB_RGB_COLORS ); > > It returns the correct number of scan lines, but tempbuffer is filled > with black. This means either the CreateDIBitmap() filled in > the bitmap > with black, or the GetDIBits() failed somehow. I can't > figure out which > is the real culprit, but the bitmap is pretty much a black square. > > Any suggestions on how to hunt this down? > > > This email is covered by the following disclaimer, please read before accepting this email. http://www.hothouse.org/disclaimer/ |