Aurigma Forums
»
Legacy Products
»
Archive
»
Other Products
»
Copy bitmap data to an 8bit grayscale windows bitmap
Rank: Member
Groups: Member
Joined: 1/5/2005(UTC) Posts: 20
|
I'm using scan0 to copy an Aurigma bitmap to a Windows Bitmap. When I use a 32bit ARGb bitmap it works just fine (piBitmapData->ConvertTo32bppArgb(255,TRUE,NULL);) But I need an 8 Bit grayscale Windows bitmap. When I convert to 8bit grayscale (piBitmapData->ConvertTo8bppGrayscale(FALSE,0,NULL);), it doesn't go into the bitmap correctly (it makes multiple small copies of itself). Here is how I create the windows bitmap: Code: piBitmapData->get_Height(&myHeight);
piBitmapData->get_Width(&myWidth);
piBitmapData->get_Scan0(&myScan0);
piBitmapData->get_BitsPerPixel(&myBitsPerPixel);
piBitmapData->get_Stride(&myStride);
piBitmapData->get_MemoryUsed(&myMemoryUsed);
CWnd* pWnd = CWnd::GetDesktopWindow();
CBitmap bitmap, bitmap2;
CWindowDC dc(pWnd);
CDC memDC;
CRect rect;
memDC.CreateCompatibleDC(&dc);
DWORD mydwCount;
mydwCount = (myHeight*myStride)-1;
bitmap.CreateBitmap(myWidth,myHeight,1,8,NULL);
bitmap.CreateCompatibleBitmap(&dc, myWidth,myHeight );// this works for 32 bit bitmaps
bitmap.SetBitmapBits(mydwCount,(void *)myScan0);
dc.SelectObject(&bitmap);
But I don't know how to tell windows to create an 8bit grayscale bitmap. If I try using the following, the bitmap comes out null: Code:bitmap.CreateBitmap(myWidth,myHeight,1,8,(void *)myScan0);
Any help would be greatly appreciated. Thanks, Ken Edited by user Sunday, December 23, 2007 6:14:41 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Member, Administration Joined: 8/2/2003(UTC) Posts: 876
Thanks: 2 times Was thanked: 27 time(s) in 27 post(s)
|
Could you tell more detailed what you want to achieve? Meanwhile, several comments: - GDI does not support 8-bit grayscale bitmaps. However it supports 8-bit indexed bitmaps with grayscale palette.
- You try to create HBITMAP using CreateCompatibleBitmap from HDC which you receive from desktop. This way you will always have 32-bit image. That's why when you copy 8-bit grayscale pixels into such bitmap, it interprets it incorrectly.
- I am not familiar with MFC wrappers for GDI functions, but I would recommend to take a look at CreateDIBSection function (or its equivalent in MFC).
|
|
|
|
Rank: Member
Groups: Member
Joined: 1/5/2005(UTC) Posts: 20
|
Thanks, I just resolved this this morning by creating a DIB (device independent bitmap), which gives full control over the pixel formats, instead of a DDB (device dependent bitmap). It works fine now. Thanks again, Ken
|
|
|
|
Aurigma Forums
»
Legacy Products
»
Archive
»
Other Products
»
Copy bitmap data to an 8bit grayscale windows bitmap
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.