troubleshooting Question

How to draw/render RAW RGB24 image buffer by using GDI+?

Avatar of Mobinex
Mobinex asked on
C++
5 Comments1 Solution1905 ViewsLast Modified:
Hi Experts,
I am beginner to use GDI+ window image library to render images.
I have used Image object to render image from file.
BUT my project that need to render buffer that captured from webcam to other place by using GDI+.
I know that we can use Image buffer with IStream but I don't know how to make it work?

Can you help me to let me know how to do this?
1. Render a buffer that captured from webcam (RGB24)
2. Real time update the buffer and render? it mean do we have any way to use stream to write for update or for each frame we need to create image object again and do render again?

Thank in advance!
bool C2DDrawing::LoadImage(BYTE* imgBuffer, int size){
//DrawingImage  Image object
	if (m_DrawingImage != NULL)
	{
		delete m_DrawingImage; m_DrawingImage = NULL;
	}
 
	HGLOBAL hBuffer;
	hBuffer = ::GlobalAlloc(GMEM_MOVEABLE,size);
 
	if(hBuffer)
	{
		void* pBuffer = ::GlobalLock(hBuffer);
		if(pBuffer)
		{
			CopyMemory(pBuffer, imgBuffer, size);
			IStream* pStream = NULL;
 
			if(::CreateStreamOnHGlobal(hBuffer,FALSE,&pStream) == S_OK)
			{
				m_DrawingImage = Gdiplus::Image::FromStream(pStream,false);
				pStream->Release();
				if(m_DrawingImage)
				{
					if(m_DrawingImage->GetLastStatus() == Ok)
					{
						UINT count = 0;
						count = m_DrawingImage->GetFrameDimensionsCount();
						GUID* pDemensionIDs = new GUID[count];
						m_DrawingImage->GetFrameDimensionsList(pDemensionIDs, count);
						m_nFrameCount = m_DrawingImage->GetFrameCount(&pDemensionIDs[0]);
						int nSize = m_DrawingImage->GetPropertyItemSize(PropertyTagFrameDelay);
						m_pPropertyItem = (PropertyItem*)malloc(nSize);
						m_DrawingImage->GetPropertyItem(PropertyTagFrameDelay, nSize, m_pPropertyItem);
						// Update Region
						int wImage = m_DrawingImage->GetWidth();
						int hImage = m_DrawingImage->GetHeight();
						m_Region = new Region(Rect(0, 0, wImage, hImage));
						delete [] pDemensionIDs;
 
						::GlobalUnlock(hBuffer);
						::GlobalFree(hBuffer);
 
					}
				}
			}
			::GlobalUnlock(hBuffer);
		}
		::GlobalFree(hBuffer);          
	}
 
	return true;
}
ASKER CERTIFIED SOLUTION
Mobinex

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros