Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Recently Having Readen Code About How to Show BMP By Operating Pixel,I
don't understand codes about Parameter(lpBits).Code As Below:

**
lpBuf=(LPBYTE)GlobalAlloc(GPTR,sizeof(BITMAPINFO)+255*sizeof(RGBQUAD)+512*512+32*32*5);
lpDIB=(LPBITMAPINFO)lpBuf;
lpRGB=(RGBQUAD*)(lpBuf+sizeof(BITMAPINFOHEADER));
lpScreen=lpBuf+sizeof(BITMAPINFOHEADER)+255*sizeof(RGBQUAD);
for (int i=0;i<5;i++)
lpChr[i]=lpScreen+512*512+32*32*i;

miHeader.biBitCount=8;
lpRGB[0].rgbRed=0;
lpRGB[0].rgbGreen=0;
lpRGB[0].rgbBlue=0;
lpRGB[1].rgbRed=128;
lpRGB[1].rgbGreen=128;
lpRGB[1].rgbBlue=128;
***

By Operating lpBuf(32*32*5),BMP Picture Changed,
I Want to know Funciton of lpBuf(32*32*5)
Posted

You're allocating memory for the image. In order to do that, you need to allocate memory for each pixel and the desired color depth of that image. That's what the 32*32*5 does.
 
Share this answer
 
To Above:
>In order to do that, you need to allocate memory for each pixel
> and the desired color depth of that image. That's what the 32*32*5 does.
Could You Tell Me How Much Is That Image(32*32?) and The depth Is 5?
 
Share this answer
 
It isn't very easy to understand why from the context, but the 32*32*5 looks like it is allocating extra memory after the bitmap for use as something else. From the variable name, I would guess it is for 5 32*32 "characters".

The 512*512 will be the size of the bitmap itself, using a 8-bit palette.

255*sizeof(RGBQUAD) is the memory for the palette - the BITMAPINFO structure contains the first RGBQUAD, which is why the 255 instead of 256.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900