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
| HBITMAP CreateRgbBitmap(LONG width, LONG height, WORD bitCount)
{
BITMAPINFO bmi = {0};
LPVOID pBits = NULL;
if(bitCount < 16 || bitCount > 32)
return NULL;
bmi.bmiHeader.cbSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, &pBits, NULL, 0);
}
HBITMAP CreateSameSizeRgbBitmap(HBITMAP source)
{
BITMAP bmp;
GetObject(source, sizeof(bmp), &bmp);
return CreateRgbBitmap(bmp.width, bmp.height, max(bmBitsPixel, 16));
}
HBITMAP Modifier_Bitmap(HBITMAP Mon_image_init, HFONT hFont, int index )
{
HBITMAP Mon_image = CreateSameSizeRgbBitmap(Mon_image_init);
HDC hdcSource = CreateCompatibleDC(NULL);
HDC hdcDest = CreateCompatibleDC(NULL);
TCHAR Message[20] = _T("");
BITMAP bmp;
wsprintf(Message, _T("Image n°%d"), index);
GetObject(Mon_image_init, sizeof(bmp), &bmp);
{
HGDIOBJ oldBmpSource = SelectObject(hdcSource, Mon_image_init);
HGDIOBJ oldBmpDest = SelectObject(hdcDest, Mon_image);
HGDIOBJ oldFont = SelectObject(hdcDest, hFont);
BitBlt(hdcDest, 0, 0, bmp.width, bmp.height, hdcSource, 0, 0, SRCCOPY);
TextOut(hdcDest, 50, 50, Message, lstrlen(Message));
SelectObject(hdcSource, oldBmpSource);
SelectObject(hdcDest, oldBmpDest);
SelectObject(hdcDest, oldFont);
}
DeleteDC(hdcDest);
DeleteDC(hdcSource);
return Mon_image;
} |
Partager