Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

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
Avatar of Mobinex
Mobinex

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

Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers