加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何列出摄像机可用的视频分辨率

发布时间:2020-12-15 06:34:45 所属栏目:百科 来源:网络整理
导读:如果我有多个摄像头连接到我的电脑…我想知道一个特定摄像机的最佳可用分辨率… 例如一些相机是高清或全高清(1,280×720像素(720p)或1,920×1080像素(1080i / 1080p))或最常见的是网络摄像机…. 我想知道摄像机工作正常的最佳视频模式…(相机使用的模式) 我
如果我有多个摄像头连接到我的电脑…我想知道一个特定摄像机的最佳可用分辨率…

例如一些相机是高清或全高清(1,280×720像素(720p)或1,920×1080像素(1080i / 1080p))或最常见的是网络摄像机….

我想知道摄像机工作正常的最佳视频模式…(相机使用的模式)

我的工作是使用C#的WPF(我正在使用Directshow)

提前致谢

解决方法

我使用它来获得最大帧大小,只是改变以适应您的需要;)
private Point GetMaxFrameSize(IPin pStill)
    {
        VideoInfoHeader v;

        IAMStreamConfig videoStreamConfig = pStill as IAMStreamConfig;

        int iCount = 0,iSize = 0;
        videoStreamConfig.GetNumberOfCapabilities(out iCount,out iSize);

        IntPtr TaskMemPointer = Marshal.AllocCoTaskMem(iSize);

        int iMaxHeight = 0;
        int iMaxWidth = 0;

        for (int iFormat = 0; iFormat < iCount; iFormat++)
        {
            AMMediaType pmtConfig = null;
            IntPtr ptr = IntPtr.Zero;

            videoStreamConfig.GetStreamCaps(iFormat,out pmtConfig,TaskMemPointer);

            v = (VideoInfoHeader)Marshal.PtrToStructure(pmtConfig.formatPtr,typeof(VideoInfoHeader));
            if (v.BmiHeader.Width > iMaxWidth)
            {
                iMaxWidth = v.BmiHeader.Width;
                iMaxHeight = v.BmiHeader.Height;
            }
            DsUtils.FreeAMMediaType(pmtConfig);

        }

        Marshal.FreeCoTaskMem(TaskMemPointer);


        return new Point(iMaxWidth,iMaxHeight);
    }


    /// <summary>
    ///  Free the nested structures and release any
    ///  COM objects within an AMMediaType struct.
    /// </summary>
    public static void FreeAMMediaType(AMMediaType mediaType)
    {
        if (mediaType != null)
        {
            if (mediaType.formatSize != 0)
            {
                Marshal.FreeCoTaskMem(mediaType.formatPtr);
                mediaType.formatSize = 0;
                mediaType.formatPtr = IntPtr.Zero;
            }
            if (mediaType.unkPtr != IntPtr.Zero)
            {
                Marshal.Release(mediaType.unkPtr);
                mediaType.unkPtr = IntPtr.Zero;
            }
        }
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读