pixels of bitmap

This is a discussion on pixels of bitmap within the Windows Programming forums, part of the Platform Specific Boards category; Hi: Sorry for the quite old topic, but I am really quite new on the bitmaps. My question is: here ...

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

    pixels of bitmap

    Hi:
    Sorry for the quite old topic, but I am really quite new on the bitmaps. My question is:
    here is:

    BYTE picturebuffer [144][176][3];

    which contains every pixel's components(red,green,blue) for a
    8-bit bitmap which has 144X176 size.

    Now I've got the picturebuffer, how can I assign the it to a bitmap and display on the screen??

    And what would be differences between
    hdc = BeginPaint(...) and hdc = GetDC(...)??
    I mean only for the hdc created by two functions.
    I would appreciate that.
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Ok, I tried with these:
    Code:
    LPBITMAPINFO bmp_info;
    
    bmp_info = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
    	bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    	bmp_info->bmiHeader.biWidth = 176;//10;//4;//176;  // width should be divided by 4
    	bmp_info->bmiHeader.biHeight = 144; // should be minus??(-144)
    	bmp_info->bmiHeader.biPlanes = 1;
    	bmp_info->bmiHeader.biBitCount = 8; 
    	bmp_info->bmiHeader.biCompression = BI_RGB; // No compression
    	bmp_info->bmiHeader.biClrUsed = 0; // When set to 0, colors used is counted on biBitCount
    I really don't know if I should use bmp_info->bmiColors[1]?
    how could I attach the known pixels' value(stored in picturebuffer) to the bmp_info?

    Thanks
    Don't laugh at me,I am just a SuperNewbie.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I'm not sure if this is exactly what you need as it's been some time since i've fiddled around with bitmap creation but you could try CreateDIBSection, an example of the use of which can be found here.

    An alternative for compatible bitmaps is SetDIBits.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Thanks, I did like that:
    Code:
    HBITMAP hPicture;
    VOID *pvBits;
    LPBITMAPINFO bmp_info;
    
    bmp_info = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
    bmp_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmp_info->bmiHeader.biWidth = 176;//10;//4;//176;  // width should be divided by 4
    bmp_info->bmiHeader.biHeight = 144; // should be maybe minus mark to make it right
    bmp_info->bmiHeader.biPlanes = 1;
    bmp_info->bmiHeader.biBitCount = 8; // 24bit colors
    bmp_info->bmiHeader.biCompression = BI_RGB; // No compression
    bmp_info->bmiHeader.biClrUsed = 0; // When set to 0, colors used is counted on biBitCount
    
    
    //create a bitmap with 176X144, 8-bit
    hPicture = CreateBitmap(176,144,1,8,&pvBits);
    
    //set the bits to bitmap handle with pictureBuffer
    SetDIBits(hdc,hPicture,49,144,&pictureBuffer,bmp_info,DIB_RGB_COLORS);
    bmp_hdc = CreateCompatibleDC(hdc);
    SelectObject(bmp_hdc,hPicture);
    BitBlt(hdc,19,49,176,144,bmp_hdc,0,0,SRCCOPY);
    
    /*pictureBuffer contains each pixel value, 
    BYTE picturebuffer [144][176][3];*/

    I am not sure if I use those parameters correctly, but It just could not display the picture,what's wrong with them? Thanks
    Don't laugh at me,I am just a SuperNewbie.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Are you running a true Windows program???

    ...with a WinProc() loop and all that Windows overhead shtuff?
    I'm not sure, but I think you need an actual window to get a handle to the device context (hdc).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loading a bitmap (Without using glaux)
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 03-16-2006, 08:43 AM
  2. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  3. bitmap pixels???????????
    By SuperNewbie in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2004, 12:53 AM
  4. bitmap not going onto screen
    By stallion in forum Windows Programming
    Replies: 4
    Last Post: 02-22-2003, 09:07 AM
  5. Saving a bitmap.
    By jdinger in forum Game Programming
    Replies: 4
    Last Post: 05-01-2002, 01:40 PM

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