c# - 使用 directshow 仅显示视频的一小部分

标签 c# video directshow directshow.net

我有一个带有 DirectShow 的 C# 视频图表。

现在我想显示所有视频源及其预览。但它不应该将视频区域调整为面板的大小。

目前它在面板上向我显示视频,但它会按比例调整视频的大小到面板中。

我只想在此面板中显示视频的单个区域。例如这张图片:http://www.cnet.de/i/story_media/41557373/weitwinkel.jpg 如果这是我的视频,其中最小的区域就是我的面板的大小。我不想让整个视频适合我的面板尺寸,它应该只显示视频的一小部分。

我的代码是:

//get the video window from the graph
IVideoWindow videoWindow2 = (IVideoWindow)_graph;

//Set the owner of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
int hr = videoWindow2.put_Owner(panel.Handle);

面板的类型为面板。

最佳答案

解决办法是使用IVideoWindow的SetWindowPosition。

//get the real video width
hr1 = videoWindow2.get_Width(out videoWidth);
DsError.ThrowExceptionForHR(hr1);

//get the real video height
hr1 = videoWindow2.get_Height(out videoHeight);
DsError.ThrowExceptionForHR(hr1);

//calculate the width when setting the height to the panel height
videoWidthF = (float)videoWidth;
videoHeightF = (float)videoHeight;
panelWidthF = (float)panelWidth;
panelHeightF = (float)panelHeight;

// calculate the margins
int margin = (int)(((panelHeightF / videoHeightF*videoWidthF) - panelWidthF) / 2);

// Position video window in client rect of main application window
hr1 = videoWindow2.SetWindowPosition(-margin, 0, (int)(panelHeightF / videoHeightF * videoWidthF), panel.Height);

关于c# - 使用 directshow 仅显示视频的一小部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924770/

相关文章:

c# - 如何使用 DataContractJsonSerializer 序列化批量数据?

c# - Microsoft 身份 - 撤销授权

c# - 为本地和域帐户获取用户所属的组

c# - 如何在 ASP.net 应用程序中结合日期时间和时区偏移量?

ios - iOS上载带有视频信息GTLServiceYoutube的视频

ios - 使用 ALAssetLibrary 从图库加载视频时未获得 Assets 值(value)

c++ - IMMDevice::Activate() 与 IBaseFilter 返回 REGDB_E_CLASSNOTREG 类未注册

javascript - 如何在 asp.net 中使用 javascript 在 Azure BLOB 存储上上传期间压缩视频?

c++ - 设置 com 类的数组会触发读取访问

c++ - 如何更改 Directshow 过滤器属性 C++