CBitmap: Want to display RGB bitmap, but can only adress G and B 
Author Message
 CBitmap: Want to display RGB bitmap, but can only adress G and B

Hi all,

I am trying to display a bitmap to the current device context by first
creating a BITMAP structure, then using
CBitmap::CreateBitmapIndirect, then
CDC::CreateCompatibleDC, then
CDC::SelectObject (CBitmap) and finally
CDC::BitBlt

This works fine so far, but I have a problem with initializing my BITMAP
structure. I want to generate an RGB bitmap, and naive as I am I thought
this would work by setting the variable bmBitPixel of the BITMAP structure
to 24 (24 Bits per Pixel), BUT this does not work. I was playing around with
the variables bmBitPixel, bmPlanes and bmWidthBytes a lot, but every time I
only get one (ONE !!!) pixel displayed. The only combination that works is
to set bmPlanes to 1, bmBitPixel to 16 and to assign an array to bmBits
where two bytes represent the color of one pixel. BUT two bytes are not
enough to dsiplay RGB. I can generate blue bitmaps or yellow bitmaps that
way, but it seems to be impossible to create a RED bitmap !!!

Has anyone an idea of how I can display a REAL RGB bitmap (without using
SetPixel or SETPixelV which is much to slow) ???

Thanks in advance
Bernd



Thu, 09 Jan 2003 03:00:00 GMT  
 CBitmap: Want to display RGB bitmap, but can only adress G and B

Hello Bernd;
I believe the problem is the current palette (default palette) is 16 color(4
bit).
Also special consideration is given to 24bit color as each pixel contains
its palette, so to speak. When you have an image that is 24 bit and trying
to display it in 256 color(8bit) you have to do special rendering.

But there is some point of confusion for me, I thought that there was an
issue of apps no-longer using palettes on the newer video drivers for
Windows 98/2000.

Or maybe it was just AnimatePalette no longer works??

Try creating and selecting a palette. Creating a 256 color palette is not
hard. You could probably find a msdn example.

Hope this helps.
Richard Jones

Quote:

>Hi all,

>I am trying to display a bitmap to the current device context by first
>creating a BITMAP structure, then using
>CBitmap::CreateBitmapIndirect, then
>CDC::CreateCompatibleDC, then
>CDC::SelectObject (CBitmap) and finally
>CDC::BitBlt

>This works fine so far, but I have a problem with initializing my BITMAP
>structure. I want to generate an RGB bitmap, and naive as I am I thought
>this would work by setting the variable bmBitPixel of the BITMAP structure
>to 24 (24 Bits per Pixel), BUT this does not work. I was playing around
with
>the variables bmBitPixel, bmPlanes and bmWidthBytes a lot, but every time I
>only get one (ONE !!!) pixel displayed. The only combination that works is
>to set bmPlanes to 1, bmBitPixel to 16 and to assign an array to bmBits
>where two bytes represent the color of one pixel. BUT two bytes are not
>enough to dsiplay RGB. I can generate blue bitmaps or yellow bitmaps that
>way, but it seems to be impossible to create a RED bitmap !!!

>Has anyone an idea of how I can display a REAL RGB bitmap (without using
>SetPixel or SETPixelV which is much to slow) ???

>Thanks in advance
>Bernd



Thu, 09 Jan 2003 03:00:00 GMT  
 CBitmap: Want to display RGB bitmap, but can only adress G and B
DDB is by design device dependent, which means different system/setting
support different kind of DDB which can have any internal format. So it's
not recommended to create initialized color DDB. Use only black/white DDB,
or DDB compatible with the DC.

For your problem, using either DIB or DIB section would easily solve your
problem. If you want GDI to render into the bitmap, use DIB section,
otherwise use DIB. Read my coming book, which has three chapters on
bitmap/advanced bitmap/image processing, one chapter on palette.

Feng Yuan

Windows Graphics Programming: Win32 GDI and DirectDraw
Amazon         http://www.amazon.com/exec/obidos/ASIN/0130869856
FatBrain
http://www1.fatbrain.com/asp/bookinfo/bookinfo.asp?theisbn=0130869856
Barnes & Noble
http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=013086...



Thu, 09 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. displaying RGB DIB on 256 colour display - palette?

2. Q: How to get RGB values from CBitmap object

3. CBitmap with rgb instead of bgr.

4. Creating a CBitmap out form an RGB-Array and putting it into MSFlexgrid

5. Why is BITMAP.bmBits NULL after CBitmap.Getbitmap(&BITMAP)

6. Wanted: How to get ethernet adress ??

7. Getting the RGB data as an array out of Bitmap

8. Set bitmap in RGB ???

9. how to display RGB data?

10. RGB in bitmap

11. RGB value of 24bit bitmap

12. Set Bitmap in RGB ???

 

 
Powered by phpBB® Forum Software