使用directshow只显示视频的一小部分

本文关键字:小部分 视频 显示 directshow 使用 | 更新日期: 2023-09-27 18:29:18

我有一个带有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);

面板的类型为panel。

使用directshow只显示视频的一小部分

解决方案是使用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);

看看使用VMR的无窗口模式。IVMRWindowlessControl9::SetVideoPosition就是您要查找的内容。快速谷歌搜索将提供样本。