PDA

View Full Version : for HBitmap from frame grabber



Unregistered
February 16, 2004, 05:58:30
Hi
i am using low cost from frame grabber Model no:-DFG/LC1

In this frame grabber i want to access pixel of bitmap direclty to memory that frame grabber saves in memory via allocation functions.
Generally i need HBitmap for it in my project . SO any can give me good code for Hbitmap from direct memory char * ?

I had also tried CDib class of Microsoft But it doesn;t seems to work .:(


Thanks

Stefan Geissler
February 16, 2004, 09:32:31
Hello,

Declare following variables:



HBITMAP m_hDIB;
BITMAPINFO m_bitmapinfo;


When you initialize the grabber, perform following:



ZeroMemory(&m_bitmapinfo, sizeof(BITMAPINFO));

is_SetColorMode (m_iFGHandle, IS_SET_CM_Y8 );
is_AllocImageMem(m_iFGHandle, 640,480,nColorDepth,&ppcImgMem,&pid);
is_AddToSequence(m_iFGHandle, ppcImgMem, pid);

is_SetImageMem (m_iFGHandle, ppcImgMem, pid);
is_SetImageSize (m_iFGHandle,640,480);
m_bitmapinfo.bmiHeader.biBitCount = nColorDepth;
m_bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFO);
m_bitmapinfo.bmiHeader.biHeight = -480;
m_bitmapinfo.bmiHeader.biWidth = 640;
m_bitmapinfo.bmiHeader.biPlanes = 1;
m_bitmapinfo.bmiHeader.biSizeImage = 640*480;

m_hDIB = CreateDIBSection(hDC, &m_bitmapinfo, DIB_RGB_COLORS,
reinterpret_cast<void**>( &ppcImgMem ), NULL, 0 );


Now you have a HBITMAP handle stored in m_hDIB. After you have grabbed an image, the HBITMAP in m_hDIB should contain the image data.

You can display the HBITMAP using following code:


HDC DestDC = m_VideoWindow.GetDC()->GetSafeHdc();
HDC SourceDC = CreateCompatibleDC( DestDC );
PCHAR mem;
PCHAR memlast;
int iNum;
RECT r;
m_VideoWindow.GetClientRect(&r);
is_GetActSeqBuf(m_iFGHandle, &iNum, &mem, &memlast);
memcpy(ppcImgMem,mem,m_bitmapinfo.bmiHeader.biSize Image);

SetStretchBltMode(DestDC,COLORONCOLOR);
SelectObject(SourceDC, m_hDIB);
StretchBlt(DestDC,
0, // XDest
0, // YDest
r.right, // source rectangle width
r.bottom, //source rectangle height
SourceDC,
0, // x-coordinate of lower-left corner of the source rect
0, // y-coordinate of lower-left corner of the source rect
640, // first scan line in array
480, // number of scan lines
SRCCOPY);
DeleteDC( SourceDC);
::ReleaseDC(m_VideoWindow.m_hWnd, DestDC);

devil20
February 16, 2004, 14:58:44
Dear Stefan

Thanks for reply
I had tried on this code but it giving me some error at line

memcpy(ppcImgMem,mem,m_bitmapinfo.bmiHeader.biSize Image);

of aceess voilations. :(

So did u tried this code on ur pc ?
OR can u make one small sample in mfc that work this code ?


If yes it would be great help for me


thanks
best regards

Stefan Geissler
February 16, 2004, 15:06:16
Hello,

you can send you sample code to support at imagingcontrol dot com, so i can have a look on it.

devil20
February 16, 2004, 15:21:12
Dear Stefan

ok i am sending my code at support@imagingcontrol.com

thaks

devil20
February 16, 2004, 15:38:22
Hi
i had sended code at ur support@imagingcontrol.com and subject is :-
for sended sample code

from nareshn2003@yahoo.com





thanks

devil20
February 17, 2004, 05:56:56
Dear Stefan

Did u got my codes with attachment of e-mail ?


thanks