应该是24位图 capGrabFrame(hWndC); // simple macro that sample a single frame from the // camera. capEditCopy(hWndC); // simple macro that edit a copy of the frame. OpenClipboard(); //like virtual memory.
//m_hBmp is a Handle to Bitmap. m_hCaptureBmp = (HBITMAP)::GetClipboardData(CF_BITMAP); CloseClipboard();
m_CaptureBmp.Detach(); //cleaning the bitmap. m_CaptureBmp.Attach(m_hCaptureBmp); //connecting the bitmap throw the handle.
directx也行.
希望有清晰解释的代码.
bmpi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpi.bmiHeader.biWidth = w;
bmpi.bmiHeader.biHeight = h;
bmpi.bmiHeader.biSizeImage = w * h * 3;
bmpi.bmiHeader.biPlanes = 1;
bmpi.bmiHeader.biBitCount = 24; FILE *fp = fopen(szFileName,"wb"); //注意要以二进制打开
if(fp) {
BITMAPFILEHEADER bfh;
bfh.bfType = 0x4d42; //(WORD)('M' << 8 | 'B');
bfh.bfSize = sizeof(BITMAPFILEHEADER) +
bmpi.bmiHeader.biSize + bmpi.bmiHeader.biSizeImage;
bfh.bfReserved1 = bfh.bfReserved2 = 0;
bfh.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + bmpi.bmiHeader.biSize;
fwrite((LPVOID) &bfh, sizeof(BITMAPFILEHEADER), 1, fp); // header
fwrite((LPVOID) &bmpi, bmpi.bmiHeader.biSize, 1, fp);
fwrite((LPVOID) pVideoData, bmpi.bmiHeader.biSizeImage, 1, fp); // data
fclose(fp);
}
怎么保存位图?
rgb的都可以阿
capGrabFrame(hWndC); // simple macro that sample a single frame from the
// camera.
capEditCopy(hWndC); // simple macro that edit a copy of the frame.
OpenClipboard(); //like virtual memory.
//m_hBmp is a Handle to Bitmap.
m_hCaptureBmp = (HBITMAP)::GetClipboardData(CF_BITMAP);
CloseClipboard();
m_CaptureBmp.Detach(); //cleaning the bitmap.
m_CaptureBmp.Attach(m_hCaptureBmp); //connecting the bitmap throw the handle.
{
//pVideoData 即 lpVHdr->lpData
}
m_InInfo.bmiHeader.biBitCount=8;
m_InInfo.bmiHeader.biClrImportant=m_InInfo.bmiHeader.biClrUsed=0;
m_InInfo.bmiHeader.biCompression=BI_RGB;
m_InInfo.bmiHeader.biHeight=240;
m_InInfo.bmiHeader.biPlanes=1;
m_InInfo.bmiHeader.biSize=0;
m_InInfo.bmiHeader.biSizeImage=0;
m_InInfo.bmiHeader.biWidth=320;
m_InInfo.bmiHeader.biXPelsPerMeter=m_InInfo.bmiHeader.biYPelsPerMeter=0; m_hWndCapture = capCreateCaptureWindow("capture window",WS_VISIBLE|WS_CHILD
,0,0,320,240,this->GetSafeHwnd(),0);
capDriverConnect(m_hWndCapture,0);
capSetVideoFormat(m_hWndCapture,&m_InInfo,sizeof(BITMAPINFO));
capPreviewRate(m_hWndCapture,40);
capPreview(m_hWndCapture,TRUE);
capSetCallbackOnFrame(m_hWndCapture,FrameCallBack); //FrameCallBack is the function nameLRESULT CALLBACK FrameCallBack(HWND hWnd, LPVIDEOHDR lpVHdr)
{
CDib dib;
BITMAPINFOHEADER m_InInfo;
m_InInfo.biBitCount=24;
m_InInfo.biClrImportant=m_InInfo.biClrUsed=0;
m_InInfo.biCompression=BI_RGB;
m_InInfo.biHeight=240;
m_InInfo.biPlanes=1;
m_InInfo.biSize=sizeof(BITMAPINFOHEADER);
m_InInfo.biSizeImage=320*240*3;
m_InInfo.biWidth=320;
m_InInfo.biXPelsPerMeter=m_InInfo.biYPelsPerMeter=0; dib.SetBitmapInfoHeader(&m_InInfo);
dib.SetDibData(CaptureData);
dib.SaveDib("C:\\d.bmp");
}
用到了CDib类 如果你没有 我可以发你邮箱一份