Advertisement

05.02.2008 at 10:25AM PDT, ID: 23372362
[x]
Attachment Details

Memory Buffer into GDI+ Image(FromStream)

Asked by M204 in C++ Programming Language

Tags: C++, C++, GDI+, IStream

I have the following code that loads a bitmap file from a zip file (using Zip Utils) and copies the memory buffer into a HGblobal, so that it can be loaded into a GDI+ Image object from a Stream.
The code compiles fine - however the bitmap is corrupt. Am I using the correct methods here?

Appreciate any thoughts or suggestions.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
void CASI::LoadResources(std::wstring strFolder)
{
	std::wstring strPath; 
	HGLOBAL hBuffer;
 
	strPath = strFolder + L"ASI.zip";
	HZIP hz = OpenZip(strPath.c_str(),0);
	ZIPENTRY ze; int i; FindZipItem(hz,L"background.bmp",true,&i,&ze);
	char *ibuf = new char[ze.unc_size];
	hBuffer = ::GlobalAlloc(GMEM_MOVEABLE,ze.unc_size);
	UnzipItem(hz, i, ibuf, ze.unc_size);
 
	if(hBuffer)
	{
		void* pBuffer = ::GlobalLock(hBuffer);
		if(pBuffer)
		{
			CopyMemory(pBuffer, ibuf, ze.unc_size);
			IStream* pStream = NULL;
 
			if(::CreateStreamOnHGlobal(hBuffer,FALSE,&pStream) == S_OK)
			{
				m_BackImage = Gdiplus::Image::FromStream(pStream,false);
				pStream->Release();
				if(m_BackImage)
				{
					if(m_BackImage->GetLastStatus() == Ok)
					{
						::GlobalUnlock(hBuffer);
						::GlobalFree(hBuffer);
					}
				}
			}
			::GlobalUnlock(hBuffer);
		}
		::GlobalFree(hBuffer);          
	}
	delete[] ibuf;
	CloseZip(hz); 
}
[+][-]05.02.2008 at 11:22AM PDT, ID: 21488872

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 11:23AM PDT, ID: 21488885

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 12:03PM PDT, ID: 21489210

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.02.2008 at 01:15PM PDT, ID: 21489737

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: C++, C++, GDI+, IStream
Sign Up Now!
Solution Provided By: JohnGaby
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628