directShow 摄像头截图,位图文件内容是黑屏?

flyfwater 2008-06-16 01:38:34
int captureMap(IBasicVideo *pBasicVideo)
{

// get width and height
long height, width;
pBasicVideo->get_VideoHeight(&height);
pBasicVideo->get_VideoWidth(&width);
long bufSize;
long *imgData;
HRESULT hr;

hr = pBasicVideo->GetCurrentImage(&bufSize, NULL);
if (FAILED(hr)) {
printf("GetCurrentImage failed\n");
return 1;
}
if (bufSize < 1) {
printf("failed to get data size\n");
return 1;
}
imgData = (long *)malloc(bufSize);
// The data will be in DIB format
pBasicVideo->GetCurrentImage(&bufSize, imgData);


// save DIB file as Bitmap.
// This sample saves image as bitmap to help
// understanding the sample.
HANDLE fh;
BITMAPFILEHEADER bmphdr;
BITMAPINFOHEADER bmpinfo;
DWORD nWritten;
memset(&bmphdr, 0, sizeof(bmphdr));
memset(&bmpinfo, 0, sizeof(bmpinfo));
bmphdr.bfType = ('M' << 8) | 'B';
bmphdr.bfSize = sizeof(bmphdr) + sizeof(bmpinfo) + bufSize;
bmphdr.bfOffBits = sizeof(bmphdr) + sizeof(bmpinfo);
bmpinfo.biSize = sizeof(bmpinfo);
bmpinfo.biWidth = width;
bmpinfo.biHeight = height;
bmpinfo.biPlanes = 1;
bmpinfo.biBitCount =24;
fh = CreateFile(L"d:\\donaldo.bmp",
GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(fh, &bmphdr, sizeof(bmphdr), &nWritten, NULL);
WriteFile(fh, &bmpinfo, sizeof(bmpinfo), &nWritten, NULL);
WriteFile(fh, imgData, bufSize, &nWritten, NULL);
CloseHandle(fh);

free(imgData);



CoUninitialize();
return 0;
}
...全文
125 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoyihui888 2008-12-27
  • 打赏
  • 举报
回复
我也遇到同样的问题啊,结果发现是第二个GetCurrentImage错误。。。MSDN上说设备暂停没有完成。。。郁闷,不知道怎么弄,你解决了吗?
flyfwater 2008-06-16
  • 打赏
  • 举报
回复
没人回答
自己顶!!

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧