MapViewOfFile and CreateDIBSection problem with bitmaps

This is a discussion on MapViewOfFile and CreateDIBSection problem with bitmaps within the Windows Programming forums, part of the Platform Specific Boards category; You might be familiar with what I'm doing if you have looked at my message on the game programming board. ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    MapViewOfFile and CreateDIBSection problem with bitmaps

    You might be familiar with what I'm doing if you have looked at my message on the game programming board. If not, I am compiling all of my resources (sounds and bitmaps) into a single file which will be loaded and parsed by the game (btw, this is not on the game programming board because it is more of a Windows question). So, one obstacle I overcame was the fact that the bitmap data must be DWORD-aligned for the liking of CreateDIBSection(). What I'm doing about that is writing all the bitmap header data, then any buffer bytes necessary (no more than 3), and then finally writing the image data.

    Everything looks well-coded and there are no problems loading the data or creating the HBITMAP with CreateDIBSection(), but when I try to blit the bitmap to the screen (in a dialog I'm just using for testing) the colors are jacked (and I don't think I just have a bad monitor, anontymouse). There are three colors in the bitmap I'm using (which displays fine when just loading it with LoadImage()), fuschia, green, and white. The fuschia and green are black when blitted and the white is grey. Clearly I don't understand what I'm doing wrong, but it obviously must be something about loading the image from a memory mapped file that it doesn't like.

    Any ideas?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Domething is going wrong with the color mapping. LoadImage() typically returns a DDB with the colors already mapped to the screen device. Color mapping for DIB sections should be performed in the BitBlt().

    Is this a 24bpp bitmap?

    How are you loading the dib section. In the typical way?
    Code:
    	HDC hdcTgt = GetDC(hwndTarget);
    	HDC hdcSrc = CreateCompatibleDC(hdcTgt);
    	SelectObject(hdcSrc, hDib);
    Could you attach a patched bitmap and I'll try it out.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    This is a 16-color image (it's a very simple game I'm working on).
    I actually just figured out how to fix it. I used DIB_RGB_COLORS instead of DIB_PAL_COLORS.
    Code:
      HDC dc = CreateCompatibleDC(NULL);
      HBITMAP hbmp = CreateDIBSection(dc, (LPBITMAPINFO)lpBMIH, DIB_RGB_COLORS,
        &pBits, hFileMap, dwOffset);

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21