Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Next is my show jpg function:
void DisplayPic(byte* imageBuffer, CDC* pDc, int nSrcWidth, int nSrcHeight, int size)
{
	IStream * pStream = NULL; 
	IPicture * pPicture = NULL; 
	HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, size); 
	LPVOID lpBuf = ::GlobalLock(hMem); 
	memcpy(lpBuf, (void*)imageBuffer, size);
	::GlobalUnlock(hMem);
	HRESULT hr = ::CreateStreamOnHGlobal(hMem, TRUE, &pStream); 
	ASSERT (SUCCEEDED(hr)); 
	hr = ::OleLoadPicture(pStream, size, FALSE, IID_IPicture, (LPVOID *)&pPicture ); 
	ASSERT(hr==S_OK); //Here failed
	pPicture->Render(pDc->m_hDC, 0, 0, nSrcWidth, nSrcHeight, 0, nSrcHeight, nSrcWidth, -nSrcHeight, NULL); 
	pPicture->Release();
	GlobalFree(hMem);
}
Posted

1 solution

Please see the sector 'Remarks' here[^] :)
 
Share this answer
 
Comments
xisiyong 3-Sep-10 7:46am    
Thanks for your answer,I know the OleLoadPicture API,But I called Failed.
Eugen Podsypalnikov 3-Sep-10 7:48am    
Do you know the supported formats listed in the section "Remarks" as well ? :)
xisiyong 3-Sep-10 7:53am    
Oh,I see the "Remarks".But I still not sure that why I can use this function show JPG file,not byte buffer.
Maybe I truly don't know it.So how I show jpg byte buffer?
Eugen Podsypalnikov 3-Sep-10 7:57am    
May be, you can build a JPG file from your buffer and then open it by an CImage object ? :)
xisiyong 3-Sep-10 8:02am    
Ok,I will try it.It's my first time come here.Nice to meet you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900