Click to See Complete Forum and Search --> : Drawing a Bitmap in Code?


April 2nd, 1999, 02:23 PM
How do I create a Bitmap in code?. I would like to dynamically create a bitmap to pass to CBrush::CreatePatternBrush .

Fabian
April 2nd, 1999, 05:03 PM
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

August 9th, 1999, 08:55 AM
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