How do I create a Bitmap in code?. I would like to dynamically create a bitmap to pass to CBrush::CreatePatternBrush .
Printable View
How do I create a Bitmap in code?. I would like to dynamically create a bitmap to pass to CBrush::CreatePatternBrush .
Hi, take a look to
HBITMAP CreateBitmapIndirect(
CONST BITMAP *lpbm // pointer to the bitmap data
);
and the structure BITMAP
typedef struct tagBITMAP { /* bm */
int bmType;
int bmWidth;
int bmHeight;
int bmWidthBytes;
BYTE bmPlanes;
BYTE bmBitsPixel;
LPVOID bmBits;
} BITMAP;
The actual bitmap is store in the array bmBits.
Good luck
Fabian
This is a sample code for creating bitmap using GDI function FillRect
Likewise you can use any GDI functions
hdc = GetDC (hwnd) ;
hdcMem = CreateCompatibleDC (hdc) ;
hBitmap = CreateCompatibleBitmap (hdc, 48,48) ;
ReleaseDC (hwnd, hdc) ;
rect.bottom = 48;
rect.left = 0;
rect.right = 48;
rect.top = 0;
SelectObject (hdcMem, hBitmap) ;
if ( !(FillRect(hdcMem,&rect,NEW_BRUSH)) )
MessageBox(hwnd,"Error","Test",MB_OK);
DeleteDC (hdcMem) ;
Please rate