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 : Saturday, October 15, 2005 1:47:21 PM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

I have a bitmap that I've created as resource. How do I get this resource into an Aurigma bitmap? It seems I should use loadfrommemory or loadfromstream, but frankly, I just can't figure out how to do this. I can easily access the bitmap as follows:

Code:
CBitmap myBitmap
myBitmap.LoadBitmap(IDB_MYBITMAP);

But I just can't figure out what to do from here. Your documentation says:

"memoryFile Specifies byte array containing file of some of supported formats. Note, this parameter should contain compressed data (for example JPEG file), not raw pixels. "

But that's not clear if it's just the bits, or requires a bitmap header, or if it's DIB or DDB or what.

Thanks for helping me in my confusion,

Ken

Edited by user Sunday, December 23, 2007 5:08:55 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Monday, October 17, 2005 2:13:08 PM(UTC)
Andrew

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)
Hello Ken,

After you load the bitmap from resources to HBITMAP, you can retrieve the image to Graphics Mill in the same way as you usually do for other HBITMAPs. E.g. through IPicture interface or copying HBITMAP data through direct memory access (see Scan0 property, etc). If you need any help with it, please let me know.

LoadFromMemory will not help in your case, because it takes a byte array with compressed data (e.g. in JPEG, TIFF, or any other file format supported by Graphics Mill).

kenberkun  
#3 Posted : Tuesday, October 18, 2005 3:38:10 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Andrew,

Last time I tried the IPicture interface I threw up my hands in dispair and gave up. Yes, I would appreciate more help!

Thanks,

Ken

Andrew  
#4 Posted : Wednesday, October 19, 2005 6:01:28 PM(UTC)
Andrew

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)
Ken,

I have wrote a quick code snippet which should help. Note, I have omitted all error handling and different situation processing for brevity. But it should give you an idea.

Please let me know if you have any problems with it.

Code:
	CBitmap mfcBitmap;
	mfcBitmap.LoadBitmap(IDB_BITMAP1);

	BITMAP bmp = {0};
	mfcBitmap.GetBitmap(&bmp);
	

	// Get access to BitmapViewer control. 
	IBitmapViewer* piBitmapViewer = NULL;
	IUnknown* piUnk = GetDlgItem(IDC_BITMAPVIEWER)->GetControlUnknown();
	HRESULT hr = piUnk->QueryInterface(IID_IBitmapViewer, (void**)&piBitmapViewer);
	if (FAILED(hr))
	{
		DisplayErrorMessage(hr);
		return;
	}

	IBitmap* piBitmap = NULL;
	hr = piBitmapViewer->get_Bitmap(&piBitmap);
	if (FAILED(hr))
	{
		DisplayErrorMessage(hr);
		return ;
	}


	PixelFormat pf;
	switch(bmp.bmBitsPixel)
	{
	case 24: 
		pf = Format24bppRgb;
		break;
	case 32:
		pf = Format32bppRgb;
		break;

	default:
		// all other cases are skipped for brevity
		piBitmap->Release();
		piBitmapViewer->Release();
		return;
	}

	piBitmap->CreateNew(bmp.bmWidth, bmp.bmHeight, pf, 0, NULL);
	IBitmapData* piBitmapData = NULL;
	piBitmap->get_Data(&piBitmapData);

	long pointerToBitmapPixels = 0;
	piBitmapData->get_Scan0(&pointerToBitmapPixels);


	mfcBitmap.GetBitmapBits(bmp.bmHeight * bmp.bmWidthBytes,(void*)pointerToBitmapPixels);
	//CopyMemory((void*)pointerToBitmapPixels, bmp.bmBits, 1);
	
	piBitmap->FireAfterChange(L"", 0);
	piBitmapData->Release();
	piBitmap->Release();
	piBitmapViewer->Release();

Edited by user Sunday, December 23, 2007 5:09:10 PM(UTC)  | Reason: Not specified

kenberkun  
#5 Posted : Friday, October 21, 2005 9:02:35 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

This worked great, thanks! You guys give excellent support.

I must admit I'm curious to understand how it would work with an IPicture interface, but only if it's not too much trouble.

Aloha,

Ken

Andrew  
#6 Posted : Friday, October 21, 2005 9:26:41 PM(UTC)
Andrew

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)
Ken,

If you are using MFC, I think there should be some wrapper classes for IPicture/IPictureDisp (since it is widely used when transferring the image to ActiveX controls). But I never dealt with MFC deeply so it is possible I am wrong.

Please find below a code snippet which uses OleCreatePictureIndirect and PICTDESC structure:

Code:
	CBitmap mfcBitmap;
	mfcBitmap.LoadBitmap(IDB_BITMAP1);	
	
	PICTDESC pictDesc={0};
	pictDesc.cbSizeofstruct = sizeof(PICTDESC);
	pictDesc.picType = PICTYPE_BITMAP;
	pictDesc.bmp.hpal = NULL;  // It is ok if you are sure that you have 24-bit or 32-bit RGB bitmaps
	pictDesc.bmp.hbitmap = mfcBitmap;

	IPictureDisp* piPict = NULL;
	hr = OleCreatePictureIndirect(&pictDesc, IID_IPictureDisp, FALSE, (void**)&piPict);
	if (FAILED(hr))
	{
		DisplayErrorMessage(hr);
		return ;
	}

	IBitmapData* piBitmapData = NULL;
	piBitmap->get_Data(&piBitmapData);

	piBitmapData->put_Picture(piPict);

	piBitmapData->ConvertTo24bppRgb(FALSE, 0, NULL);
	piBitmap->FireAfterChange(L"", 0);
	 
	piBitmapData->Release();
	piBitmap->Release();
	piBitmapViewer->Release();
	piPict->Release();

Note, I have converted the result image to 24-bit format intentionally. GDI does not know anything about alpha channel and when HBITMAP is 32-bit RGB, the high byte of each pixel is zero (i.e. it is interpreted by Graphics Mill as transparent). To avoid this, I discard the alpha channel.

Hope this helps.

Edited by user Sunday, December 23, 2007 5:09:24 PM(UTC)  | Reason: Not specified

kenberkun  
#7 Posted : Tuesday, October 25, 2005 9:58:08 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Thanks! Again, you guys are awesome.

Ken

Users browsing this topic
Guest (2)
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.