Thread: Create a Bitmap

  1. #1
    Registered User
    Join Date
    Sep 2001

    Create a Bitmap


    On the window, I created a rectangle and filled it with a brush, now I want to save it in HBTIMAP and display it again on window

    so, first I created a rectangle
    HDC hdc,bmp_hdc;
    HBITMAP hPicture;
    hdc = BeginPaint(hwnd, &ps);
    hBrush = CreateSolidBrush(RGB(230,230,230));	// Creating brush for background
    SelectObject(hdc, hBrush);				
    Rectangle(hdc, 19, 49, 196, 194); // Drawing rectange that is 1 pixel larger than picture in every dimension
    /*The rectangle was created and filled with color,
    secondly, created a BITMAPINFO structure;*/
    BITMAPINFO bmp_info;
    ZeroMemory( &bmp_info.bmiHeader, sizeof(BITMAPINFOHEADER) );
    bmp_info.bmiHeader.biWidth = 16;//10;//4;//176;  // width should be divided by 4
    bmp_info.bmiHeader.biHeight = 16; // should be maybe minus mark to make it right
    bmp_info.bmiHeader.biPlanes = 1;
    bmp_info.bmiHeader.biBitCount = 8; // 24bit colors
    bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmp_info.bmiHeader.biSizeImage = 0; 
    bmp_info.bmiHeader.biCompression = BI_RGB; // No compression
    bmp_info.bmiHeader.biClrUsed = 0; // When set to 0, colors used is counted on biBitCount
    bmp_info.bmiHeader.biClrImportant= 0;
    /*rest of the codes, I did like this:*/
    bmp_hdc = CreateCompatibleDC(hdc);
    hPicture = CreateDIBSection(hdc, &bmp_info, DIB_RGB_COLORS,NULL,NULL,0);
    //now I copy size 16X16 from that rectangle to hPicture
    16, NULL, (BITMAPINFO*)&bmp_info, DIB_RGB_COLORS);
    //again, show the hPicture in position (20,30) back in hdc

    but I could not display what I had copied from that rectangle, what's wrong with my code, thanks!!!!
    Sorry for un-clear codes!!
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Thanks, I got it, just the problem with
    bmp_info.bmiHeader.biBitCount = 8;
    /*it should be*/
    bmp_info.bmiHeader.biBitCount = 24;
    Don't laugh at me,I am just a SuperNewbie.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Try this:

    hBrush = CreateSolidBrush(RGB(230,230,230));
    hOldBrush = SelectObject(hdc, hBrush);
    Rectangle(hdc, 19, 49, 196, 194);
    SelectObject(hdc, hOldBrush);
    bmp_hdc = CreateCompatibleDC(hdc);
    hPicture = CreateCompatibleBitmap(hdc, 16, 16);
    hOldPicture = SelectObject(bmp_hdc,hPicture);
    SelectObject(bmp_hdc, hOldPicture);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap Displaying Problem
    By MadCow257 in forum Game Programming
    Replies: 0
    Last Post: 01-25-2005, 05:21 PM
  2. ResHacker error replacing bitmap file
    By 7stud in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2004, 07:54 AM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Loading a Bitmap resource for OpenGL Texture[x]
    By the dead tree in forum Game Programming
    Replies: 4
    Last Post: 08-26-2004, 01:12 PM
  5. graphics in win32 API
    By bennyandthejets in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2002, 01:10 AM