Mobinex
asked on
How to draw/render RAW RGB24 image buffer by using GDI+?
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!
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;
}
Why don't you try to use DirectShow? If you want the image frame, you can add SampleGrabber filter right after the webcam source filter and use NullRenderer filter in the end (if that is intended).
If you just want to show the live video from a webcam in your own window, create a directshow graph containing the webcam source filter, let DirectShow find the filters needed and in the end of the graph there will be a VideoRenderer. Put your window handle in the VideoRenderer and start to play.
Here is a link how to use SampleGrabber:
http://www.codeproject.com/KB/audio-video/framegrabber.aspx
If you just want to show the live video from a webcam in your own window, create a directshow graph containing the webcam source filter, let DirectShow find the filters needed and in the end of the graph there will be a VideoRenderer. Put your window handle in the VideoRenderer and start to play.
Here is a link how to use SampleGrabber:
http://www.codeproject.com/KB/audio-video/framegrabber.aspx
ASKER
Yah, I know these way BUT my project is using GDI+ for project images, the example above just for explaining.
My functions that need to receive webcam buffer (format 320x240, RGB24), process this buffer and return back. finally i will get return buffer to show to the control, the buffer will send at real-time to my function so it is always updated.
My question is that if we have any function that is using GDI+ to update the buffer (not create new image or bitmap) for each render.
Any help again?
Tx
My functions that need to receive webcam buffer (format 320x240, RGB24), process this buffer and return back. finally i will get return buffer to show to the control, the buffer will send at real-time to my function so it is always updated.
My question is that if we have any function that is using GDI+ to update the buffer (not create new image or bitmap) for each render.
Any help again?
Tx
If our webcam is using DirectShow, there is no other way than using DirectShow to access the buffer.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
It might be possible to copy each fram's data directly into a DIB Section and then blit it to the screen.