Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

using SetDIBits( ) in Win32

This topic is 5155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I have a file that stores a bitmap''s raster buffer as part of its data. When my program runs, I load this information out of the file and store it as an array of unsigned char''s. Now I need to put it on a window. I''ve been trying to use SetDIBits( ) from the Win32 SDK but the drawing doesn''t happen. Below is my code:
/*///////////////////////////////////////////////////////////////
** NOTES: hdc is a paramater to the specific draw function
** that I''m calling herein.  The function is also passed an
** HWND of the window it''s drawing on.  The function should
** draw on the DC and return it by reference.  
**
** The class Graphic has a function DumpGraphic which returns
** a pointer to the byte buffer.  Bad practice, yes, but this
** was only written in absence of my real code which makes a 
** copy of the buffer (I''m on a break for the holiday, away from 
** my real code :)).
*////////////////////////////////////////////////////////////////

void DrawManager::UpdateAll(HDC& hdc,
                            HWND hwnd,
                            int nRow,    //how many in a row

                            int nHeight, //how many rows

                            int nImgSize)//sq. pixel count of img

{
    //width-height is in pixels

    //depth is bits per pixel

    //size is in bytes of total image

    //since all gfx are same get attributes of first one

    //function returns paramaters by reference

    int width,height,depth,size;
    ((Graphic*)(m_ptrnvBitmaps[0]))->DumpAttributes(width,height,depth,size);

    //set up an info header to sent to SetDIBits()

    BITMAPINFOHEADER bmih;
    bmih.biSize = sizeof(BITMAPINFOHEADER);
    bmih.biBitCount = depth;
    bmih.biClrImportant = 0;
    bmih.biClrUsed = 0;
    bmih.biCompression = BI_RGB;
    bmih.biHeight = height;
    bmih.biWidth = width;
    bmih.biPlanes = 1;
    bmih.biSizeImage = size;
    bmih.biXPelsPerMeter = 0;
    bmih.biYPelsPerMeter = 0;
	
    //for SetDIBits()

    BITMAPINFO bmi;
    bmi.bmiHeader = bmih;



    hdc = GetDC(hwnd);
	
    for(int y=0; y<nHeight; y++){
        for(int x=0; x<nRow; x++){
            HDC hTempDC = CreateCompatibleDC(hdc);
            HBITMAP hTempBMP = CreateCompatibleBitmap(hdc,size,size);	

            //problem must be here

            //DumpGraphic() returns an unsigned char*

            SetDIBits(hTempDC,hTempBMP,0,nImgSize,
              ((Graphic*)(m_ptrnvBitmaps[(y*nRow)+x]))-> 
                DumpGraphic(),&bmi,DIB_RGB_COLORS);

            BitBlt(hdc,x,y,
            x+nImgSize,y+nImgSize,     
            hTempDC,nImgSize,nImgSize,SRCCOPY);
            }
        }

    ReleaseDC(hwnd,hdc);
    return;
}
I put this in the WM_PAINT handler of the window and pass it a DC and HWND from there, but my output is nothing. I''ve checked the Graphic class'' Load() (not shown here) and DumpGraphic() (used in the SetDIBits() call), and they all work the way they''re supposed to and get valid data. I suspect the problem lies with the BITMAPINFO structure I create to pass to the SetDIBits() call. I purposely didn''t fill in the RGBQUAD element because the image loaded is 24 bit. Any input on the problem would be greatly appreciated.
_________________
:: MajorShredd ::
The glass is neither half full nor half empty;
rather, it is a combination of both, and the system is perfect.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I''ve only glanced over the code briefly, but it appears that your code lacks any call to SelectObject().

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!