Create a Bitmap

This is a discussion on Create a Bitmap within the Windows Programming forums, part of the Platform Specific Boards category; Hi On the window, I created a rectangle and filled it with a brush, now I want to save it ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Create a Bitmap

    Hi

    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
    Code:
    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
    				
    DeleteObject(hBrush);
    
    /*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);
    SelectObject(bmp_hdc,hPicture);
    
    //now I copy size 16X16 from that rectangle to hPicture
    BitBlt(bmp_hdc,0,0,16,16,hdc,19,49,SRCCOPY);
    16, NULL, (BITMAPINFO*)&bmp_info, DIB_RGB_COLORS);
    
    //again, show the hPicture in position (20,30) back in hdc
    BitBlt(hdc,20,30,16,16,bmp_hdc,0,0,SRCCOPY);

    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
    Posts
    173
    Thanks, I got it, just the problem with
    Code:
     
    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
    Posts
    2,544
    Try this:

    Code:
    hBrush = CreateSolidBrush(RGB(230,230,230));
    hOldBrush = SelectObject(hdc, hBrush);
    Rectangle(hdc, 19, 49, 196, 194);
    SelectObject(hdc, hOldBrush);
    DeleteObject(hBrush);
    
    bmp_hdc = CreateCompatibleDC(hdc);
    hPicture = CreateCompatibleBitmap(hdc, 16, 16);
    hOldPicture = SelectObject(bmp_hdc,hPicture);
    
    BitBlt(bmp_hdc,0,0,16,16,hdc,19,49,SRCCOPY);
    
    BitBlt(hdc,20,30,16,16,bmp_hdc,0,0,SRCCOPY);
    
    SelectObject(bmp_hdc, hOldPicture);
    DeleteObject(hPicture);
    DeleteDC(bmp_hdc);

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, 04:21 PM
  2. ResHacker error replacing bitmap file
    By 7stud in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2004, 06: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21