Getdibits help

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to get the bits of a 1bpp bitmap using getDIBits using this code:

<div style="color:Black;background-color:White; <pre>
HDC dcmem=NULL;
PBYTE buf=NULL;
LPBITMAPINFO bmpInfo;
HBITMAP bmpfile = NULL;
<span style="color:Blue; int dibLineCount;

<span style="color:Green; //load bitmap
bmpfile = (HBITMAP)LoadImageA(NULL, FILENAME, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
<span style="color:Blue; if(!bmpfile)
{
<span style="color:Green; //Load Image failed
<span style="color:Blue; return 0;
}

<span style="color:Green; //select bitmap to dc
dcmem = CreateCompatibleDC ( NULL );
<span style="color:Blue; if (NULL==SelectObject(dcmem,bmpfile))
{
<span style="color:Green; //select object failed
DeleteDC(dcmem);
<span style="color:Blue; return 0;
}


bmpInfo = (LPBITMAPINFO)calloc(1,<span style="color:Blue; sizeof(BITMAPINFO));
bmpInfo->bmiHeader.biSize=<span style="color:Blue; sizeof(BITMAPINFOHEADER);

<span style="color:Green; //getDIBits to fill bmpInfo
dibLineCount = GetDIBits(dcmem,bmpfile,0,0,NULL,bmpInfo,DIB_RGB_COLORS);
<span style="color:Blue; if(dibLineCount == 0)
{
<span style="color:Green; //getdibits 1 failed
DeleteDC(dcmem);
free(bmpInfo);
<span style="color:Blue; return 0;
}

<span style="color:Blue; if(bmpInfo->bmiHeader.biSizeImage <= 0)
bmpInfo->bmiHeader.biSizeImage=bmpInfo->bmiHeader.biWidth*abs(bmpInfo->bmiHeader.biHeight)*(bmpInfo->bmiHeader.biBitCount+7)/8;


<span style="color:Blue; if((buf = (PBYTE)malloc(bmpInfo->bmiHeader.biSizeImage)) == NULL)
<span style="color:Blue; return 0;

bmpInfo->bmiHeader.biCompression =BI_RGB;

<span style="color:Green; //get bits
dibLineCount = GetDIBits(dcmem,bmpfile,0,bmpInfo->bmiHeader.biHeight,buf,bmpInfo,DIB_RGB_COLORS);
<span style="color:Blue; if(dibLineCount == 0)
{
<span style="color:Green; //getdibits 2 failed
DeleteDC(0,dcmem);
free(buf);
free(bmpInfo);
<span style="color:Blue; return 0;
}
[/code]
<br/>
<br/>
Then I send the bits using winsock to another PC. But everytime I send the packet with the bits I see the bits only contain periods "..." or FF in hex which is very weird. I see that the second call to getDIBits returns the correct amount of lines scanned though.
Can anyone help me why the bits are like this? Any help would be appreciated.



View the full article
 
Back
Top