1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| /* Function to create a 16-Color DIB with standard VGA colors
---------------------------------------------------------- */
HBITMAP CreateStandard16ColorDIB(
int const xSize, //[in] width
int const ySize, //[in] height
LPVOID * const pt_pt_bits //[out] receives a pointer to the bitmap binary data
)
{
HBITMAP hBmpReturn = NULL; //[out] handle to the newly created bitmap
//Bitmap info for creation
char bufBmpInfo[sizeof(BITMAPINFOHEADER)+16*sizeof(RGBQUAD)];
PBITMAPINFO const pbmi = (PBITMAPINFO)bufBmpInfo;
RGBQUAD * const pClr = pbmi->bmiColors;
//Initialize the BITMAPINFO struct
ZeroMemory(pbmi, sizeof(BITMAPINFOHEADER)+16*sizeof(RGBQUAD));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biBitCount = 4; //4 bit/pixel (16 colors)
pbmi->bmiHeader.biClrImportant = 0; //use all colors
pbmi->bmiHeader.biClrUsed = 0; //use all colors
pbmi->bmiHeader.biCompression = BI_RGB; //No compression
pbmi->bmiHeader.biHeight = ySize; //bitmap height
pbmi->bmiHeader.biPlanes = 1; //Aways 1 plane for DIBs
pbmi->bmiHeader.biSizeImage = 0;
pbmi->bmiHeader.biWidth = xSize; //bitmap width
pbmi->bmiHeader.biXPelsPerMeter = 0;
pbmi->bmiHeader.biYPelsPerMeter = 0;
//Fill the DIB color palette with the 16 standard VGA colors
pClr[ 0].rgbRed= 0 ; pClr[ 0].rgbGreen= 0 ; pClr[ 0].rgbBlue= 0; //Black #000000
pClr[ 1].rgbRed= 0 ; pClr[ 1].rgbGreen= 0 ; pClr[ 1].rgbBlue=128; //Blue #000080
pClr[ 2].rgbRed= 0 ; pClr[ 2].rgbGreen=128 ; pClr[ 2].rgbBlue= 0; //Green #008000
pClr[ 3].rgbRed= 0 ; pClr[ 3].rgbGreen=128 ; pClr[ 3].rgbBlue=128; //Cyan #008080
pClr[ 4].rgbRed=128 ; pClr[ 4].rgbGreen= 0 ; pClr[ 4].rgbBlue= 0; //Red #800000
pClr[ 5].rgbRed=128 ; pClr[ 5].rgbGreen= 0 ; pClr[ 5].rgbBlue=128; //Magenta #800080
pClr[ 6].rgbRed=128 ; pClr[ 6].rgbGreen=128 ; pClr[ 6].rgbBlue= 0; //Yellow/Brown#808000
pClr[ 7].rgbRed=192 ; pClr[ 7].rgbGreen=192 ; pClr[ 7].rgbBlue=192; //Light Grey #C0C0C0
pClr[ 8].rgbRed=128 ; pClr[ 8].rgbGreen=128 ; pClr[ 8].rgbBlue=128; //Dark Grey #808080
pClr[ 9].rgbRed= 0 ; pClr[ 9].rgbGreen= 0 ; pClr[ 9].rgbBlue=255; //Bright Blue #0000FF
pClr[10].rgbRed= 0 ; pClr[10].rgbGreen=255 ; pClr[10].rgbBlue= 0; //Bright Green #00FF00
pClr[11].rgbRed= 0 ; pClr[11].rgbGreen=255 ; pClr[11].rgbBlue=255; //Bright Cyan #00FFFF
pClr[12].rgbRed=255 ; pClr[12].rgbGreen= 0 ; pClr[12].rgbBlue= 0; //Bright Red #FF0000
pClr[13].rgbRed=255 ; pClr[13].rgbGreen= 0 ; pClr[13].rgbBlue=255; //Bright Magenta#FF00FF
pClr[14].rgbRed=255 ; pClr[14].rgbGreen=255 ; pClr[14].rgbBlue= 0; //Bright Yellow #FFFF00
pClr[15].rgbRed=255 ; pClr[15].rgbGreen=255 ; pClr[15].rgbBlue=255; //Bright White #FFFFFF
//Create the DIB
hBmpReturn = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, pt_pt_bits, NULL, 0);
return hBmpReturn;
} |
Partager