Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
kenberkun  
#1 Posted : Thursday, May 26, 2005 3:38:00 PM(UTC)
kenberkun

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

Andrew  
#2 Posted : Friday, May 27, 2005 5:04:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
Could you tell more detailed what you want to achieve?

Meanwhile, several comments:
  1. GDI does not support 8-bit grayscale bitmaps. However it supports 8-bit indexed bitmaps with grayscale palette.
  2. 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.
  3. 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).
kenberkun  
#3 Posted : Saturday, May 28, 2005 7:08:00 AM(UTC)
kenberkun

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
Users browsing this topic
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.