camera->DrawFrame() in new SDK

Post Reply
avelazquez
Posts: 19
Joined: Mon Jun 07, 2010 7:40 am

camera->DrawFrame() in new SDK

Post by avelazquez » Sun Nov 14, 2010 10:23 pm

I am porting my application to the new SDK, however I am having trouble displaying the image on a vc++ picturebox.

I am using the following:

frame->Rasterize(640,480,640,8,imageBuffer);

however once I have the imageBuffer I don't know what to do with it in order to display this on a picturebox.

With the old SDK I could use the following:
camera->DrawFrame(NewFrame, (long)tempHandle);

where tempHandle is a handle to the picturebox

Thank You for any Help!

VincentG
Posts: 7728
Joined: Mon Jul 17, 2006 5:00 am
Location: Corvallis, Oregon

Re: camera->DrawFrame() in new SDK

Post by VincentG » Mon Nov 15, 2010 3:34 pm

Essentially, the rasterize function lets you populate a memory buffer with image data. It's designed so that you can specify 8,16,24, or 32 bit per pixel formats and varying row spans as well, which covers nearly 100% of the use patterns.

One of the most user friendly ways to manage this image data is to create one of our CameraLibrary::Bitmap objects, like we do in the sample code you're using, and rasterize into it. Our Bitmap class also has a 'GetBits' method which allows the user to get a pointer to the raw data which can then be pumped over to a CBITMAP for example for pushing to the UI.

Here's a little snippit of code that we've used in the past that should help you get the data into your object for display.


void DrawBitmap( Frame *frame, HWND hwnd )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd * pWnd = CWnd::FromHandle(hwnd);

pWnd->GetWindowRect(&m_rectBitmap);
POINT pt;

pt.x = m_rectBitmap.left;
pt.y = m_rectBitmap.top;

ScreenToClient(hwnd, &pt);

if ( !pWnd->GetSafeHwnd() )
return;

CClientDC dc(pWnd);
int colorDepth = dc.GetDeviceCaps( BITSPIXEL );

m_viewBitmap.DeleteObject();
m_viewBitmap.CreateBitmap( m_bitmap->PixelWidth(), m_bitmap->PixelHeight(), 1, m_bitmap->GetBitsPerPixel(), 0 );

pWnd->Invalidate();

frame->Rasterize(m_bitmap);

m_viewBitmap.SetBitmapBits( m_bitmap->PixelWidth() * m_bitmap->PixelHeight() * m_bitmap->GetBytesPerPixel(), m_bitmap->GetBits() );

BITMAP bm;
m_viewBitmap.GetBitmap( &bm );

CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject( &m_viewBitmap );

dc.BitBlt(pt.x, pt.y, m_bitmap->PixelWidth(), m_bitmap->PixelHeight(), &memDC, 0,0, SRCCOPY);
}

Post Reply