directShow 摄像头截图,位图文件内容是黑屏?
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;
}
{
// 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;
}
...全文
相关推荐
directshow摄像头采样
本程序是用directshow写的一个摄像头采样小东东,主体框架是仿照网上的capture类 支持不断截图,截图存于c盘当前目录,嘿嘿,随意修改啦,共勉!
C#实现摄像头显示,截图
C#语言编写 vs2005 关于摄像头显示 和qq相似, 功能用于截图,录影,方便大家学习用
c#摄像头显示截图源码
自动实别电脑摄像头硬件,动态摄像内容,对摄像内容指定范围截屏,有源码可参考
C#操作摄像头(打开、关闭、截图)_C#操作摄像头_
C# 操作摄像头、打开、关闭、截图。完整程序代码。
c# 实现网络摄像头预览以及截图,采用ICaptureGraphBuilder2 方式直接找寻接口
c# 实现网络摄像头预览以及截图,采用ICaptureGraphBuilder2 方式直接找寻接口 简化了Pin直接的连接,采用Pin连接输出视频流的方式会在下一份代码中实现


多媒体/流媒体开发
