您的位置:首页 > 其它

DirectShow:图片的抓取---从摄像头流中捕捉一张图片zzDirectshow中的视频捕捉

2012-08-08 17:06 519 查看
在播放媒体文件的过程中,有一个很有用的功能,就是在当前播放的位置抓取图,实现这种图片抓取功能的方法很多,我们这里只介绍常用的两种。 

第1种方法最简单,它使用1BasicVideo::GetCurrentImage接口方法,代码如下。 

   heel SnapshotBitmap(IBasicVideo*pBa8icVideo,  const char*OutFile)

    if  (pBasicVldeo)

    {

        long bitmapSize=0;

        //首先获得图像大小

        if(SUCCEEDED(pEasicVidee->GetcurrentImage(&bitmapSize,0)))

        {

            bool pass=false;

            //分配图像帧内存

            unsigned char*buffer=new unsigned char[bitmapSize];

           //获取图像帧数据

           if(SUCCEEDED(pBasicVideo->GetCurrentImage(&bitmapSize,(long*)buffer)))

     {

               BITMAPFILEHEADER hdr;

               LPBITMAPINFOHEADER  ipbi;

               ipbi=(LPBITMAPINFOHEADER)buffer;

               int nColors=1<<ipbi->biBitCount;

               if(nColors>256)

               //always is”BM”

                hdr.bfType    =((WORD)(‘M’<<8)|’B’);

                hdr.bfSize    =bitmapSize+sizeof(hdr);

                hdr.bfReservedl    =0;

                hdr.bfReserved2   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息