Zoom feature can be reached with "crop" property and changing a source video format. After you crop the original video, the result frame is stretched to the preview control (or to the specified video format), so after "crop" property is specified, you should change a video format. Here is an article about conversion.
For example, let's imagine 2 sliders (track bars) to make zoom by horizontal (zoomX) and by vertical (zoomY) axes.
MFormats SDK
The moment you change the value of these sliders you should call a code similar to this:
m_objMFReader.PropsSet("crop", zoomX.Value + "," + zoomY.Value + "," + zoomX.Value + "," + zoomY.Value); string width; string height; m_objMFReader.PropsGet("info::video.0::width", out width); m_objMFReader.PropsGet("info::video.0::height", out height); props.vidProps.eVideoFormat = eMVideoFormat.eMVF_Custom; props.vidProps.eScaleType = eMScaleType.eMST_IgnoreAR; props.vidProps.nWidth = Convert.ToInt32(width, CultureInfo.InvariantCulture) - 2 * zoomX.Value; props.vidProps.nHeight = Convert.ToInt32(height, CultureInfo.InvariantCulture) - 2 * zoomY.Value;
With the PropsSet method, a "crop" parameter is specified in "left, top, right, bottom" style. See this article to get more information.
The original resolution is received with the PropsGet method. And this value is used to specify new width and height for M_AV_PROPS structure (props in the above code). This structure is used for the SourceFrameConvertedGet method to get video.
Another way is to crop a source frame separately with the MFCut method. This method cuts a rectangle part of an original frame and has the following parameters:
- _nField - a number of a field to cut (0 means both fields, 1 means the first field, 2 means the second one)
- _pRect - a rectangle for cutting
- _ppFrameRes - result frame object
Here is an example of how to cut 100 pixels from each side of a source frame:
MFFrame pFrame = null; m_objLive.SourceFrameGet(-1, out pFrame, ""); tagRECT rect = new tagRECT {bottom = 980, left = 100, right = 1820, top = 100}; MFFrame cutFrame; pFrame.MFCut(0, ref rect, out cutFrame);
You can connect tagRECT structure fields with sliders.
You can read about tagRECT structure in this article.
MPlatform SDK
With MPlatform you should use the "object::crop" property for your object to emulate zoom feature. And you should specify a video format.
The code looks like:
// get an original structure to obtain width and height of a source object: M_VID_PROPS props; string formatName; int formatIndex; // even if there is no conversion, this method returns you parameters of a result video. m_objFile.FormatVideoGet(eMFormatType.eMFT_Convert, out props, out formatIndex, out formatName); // specify cropping parameter value string cropValue = zoomX.Value + "," + zoomY.Value + "," + zoomX.Value + "," + zoomY.Value; m_objFile.PropsSet("object::crop", cropValue); // change video format props.eVideoFormat = eMVideoFormat.eMVF_Custom; props.eScaleType = eMScaleType.eMST_IgnoreAR; props.nWidth = props.nWidth - 2 * zoomX.Value; props.nHeight = props.nHeight - 2 * zoomY.Value; // set the video format m_objFile.FormatVideoSet(eMFormatType.eMFT_Convert, ref props);