jdl
jdl

Reputation: 6323

GetDIBits: bitmap modifications, but crashes out?

GetDIBits: trying to modify the bitmap, but not sure how to go about it? I tried lpvBits but it crashes out in the comparison in the "pig" area. How should I do this? thx

LPVOID lpvBits=NULL;    // pointer to bitmap bits array 
BITMAPINFO bi; 

ZeroMemory(&bi.bmiHeader, sizeof(BITMAPINFOHEADER)); 
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 

if (!GetDIBits(dc, m_bmp, 0, 400, lpvBits, &bi, DIB_RGB_COLORS)) 
AfxMessageBox("1");


char *pig = (char*)lpvBits;

for (int m=0;m<100;m++)
{
    if (pig[m] > 100)
    {
        pig[m] = 250;
    }
}

SetDIBits( dc, m_bmp, 0, 400, (void *)pig, &bi, DIB_RGB_COLORS ); 

Upvotes: 0

Views: 538

Answers (2)

jdl
jdl

Reputation: 6323

http://msdn.microsoft.com/en-us/library/dd144879(v=vs.85).aspx

lpvBits [out] A pointer to a buffer to receive the bitmap data. If this parameter is NULL, the function passes the dimensions and format of the bitmap to the BITMAPINFO structure pointed to by the lpbi parameter.

example found here: http://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/ms969901.aspx

http://www.codeproject.com/KB/graphics/drawing2bitmap.aspx

http://www.cplusplus.com/forum/general/28469/

Upvotes: 1

Jason Williams
Jason Williams

Reputation: 57902

Read the documentation for GetDIBits carefully - the lpvBits pointer is not returned to you - you need to allocate enough memory for the bitmap data you want to fetch, and pass it to GetDIBits to fill it in with image data.

Upvotes: 0

Related Questions