CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Drawing a Bitmap in Code?

    How do I create a Bitmap in code?. I would like to dynamically create a bitmap to pass to CBrush::CreatePatternBrush .


  2. #2
    Join Date
    Apr 1999
    Posts
    21

    Re: Drawing a Bitmap in Code?

    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


  3. #3
    Guest

    Re: Drawing a Bitmap in Code?

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured