2

I have a video graph in c# with DirectShow.

Now I want to show all video sources with its preview. But it should not adjust the video area to the size of the panel.

Currently it shows me the video on the panel, but it adjust the size of the video proportional into the panel.

I want to show only a single area of the video in this panel. For example this picture: http://www.cnet.de/i/story_media/41557373/weitwinkel.jpg If this would be my video and the smallest area on it would be the size of my panel. I don't want to fit the whole video in my panel size, it should only show a small part of the video.

My code is:

//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 is of type Panel.

lszrh
  • 1,531
  • 1
  • 19
  • 28

2 Answers2

2

The solution is to use SetWindowPosition of IVideoWindow.

//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);
lszrh
  • 1,531
  • 1
  • 19
  • 28
1

Take a look at using windowless mode of the VMR. IVMRWindowlessControl9::SetVideoPosition is what you are looking for. A quick google search would provide samples.

Saibal
  • 802
  • 6
  • 15