public object Format { get; } public:property Object^ Format {Object^ get();}
An object representing the format buffer.
This property allows direct access to the format buffer for in-process servers. However, if the interface is marshaled across process boundaries, then the client will only be accessing a copy of the data. In such a case, the client should call SetFormatData to alter the contents of the format buffer. The array cannot be resized. To resize the format buffer, set the FormatSize property and then access the MediaType.Format property again.
using Leadtools;using Leadtools.Multimedia;using LeadtoolsMultimediaExamples.Fixtures;public bool _result = false;public ConvertCtrlForm _form = new ConvertCtrlForm();public void FormatExample(){// reference the convert controlConvertCtrl convertCtrl = _form.ConvertCtrl;// input file and output filesstring inFile = Path.Combine(LEAD_VARS.MediaDir, "ConvertCtrl_ShortSource.avi");string outFilePfx = Path.Combine(LEAD_VARS.MediaDir, "MediaType_FormatExample");// This example demonstrates how to use SampleTarget and MediaSample// objects to directly access sample frames from a conversion graph.try{// set the source and target filesconvertCtrl.SourceFile = inFile;// set the previewconvertCtrl.Preview = true;// create a new sample targetSampleTarget sampleTarget = new SampleTarget();// set the target media type for the video streamMediaType targetMediaType = new MediaType();targetMediaType.Type = Constants.MEDIATYPE_Video;targetMediaType.SubType = Constants.MEDIASUBTYPE_RGB24;// set the sample target's accepted media typesampleTarget.SetAcceptedMediaType(targetMediaType);// assign the sample target to the capture controlconvertCtrl.TargetObject = sampleTarget;convertCtrl.TargetFormat = TargetFormatType.StillImage;// run the convertconvertCtrl.StartConvert();// get and process each meda sample delivered to the convertCtrlMediaSample mediaSampleFrame = sampleTarget.GetSample(1000);while (mediaSampleFrame != null){// demonstrates copying a MediaType's object propertiesMediaType mediaTypeCopy = new MediaType();using (MediaType mediaTypeSample = sampleTarget.GetConnectedMediaType()){int mediaTypeFormatSize = mediaTypeSample.FormatSize;if (mediaTypeFormatSize > 0)mediaTypeCopy.SetFormatData(mediaTypeFormatSize, mediaTypeSample.Format);elsemediaTypeCopy.FormatSize = 0;mediaTypeCopy.Type = mediaTypeSample.Type;mediaTypeCopy.SubType = mediaTypeSample.SubType;mediaTypeCopy.FormatType = mediaTypeSample.FormatType;mediaTypeCopy.FixedSizeSamples = mediaTypeSample.FixedSizeSamples;mediaTypeCopy.TemporalCompression = mediaTypeSample.TemporalCompression;mediaTypeCopy.SampleSize = mediaTypeSample.SampleSize;}// get the bitmap info from the video information headerVideoInfoHeader videoInfoHeader = mediaTypeCopy.GetVideoFormatData();int pixelSize = (int)Math.Log((double)videoInfoHeader.bmiHeader.biBitCount);int bitmapSize = (videoInfoHeader.bmiHeader.biWidth * pixelSize + pixelSize & ~3) * videoInfoHeader.bmiHeader.biHeight;// create a bitmap to hold the sample and copy itBitmap bitmap = new Bitmap(videoInfoHeader.bmiHeader.biWidth, videoInfoHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);Marshal.Copy(mediaSampleFrame.Buffer, 0, bitmapData.Scan0, bitmapSize);bitmap.UnlockBits(bitmapData);// flip the upside down bufferbitmap.RotateFlip(RotateFlipType.Rotate180FlipX);// get media time which correspond to frame numbers in videomediaSampleFrame.GetTime(out long timeStart, out long timeStop);// save the imagebitmap.Save(string.Format("{0}_{1}-{2}.bmp", outFilePfx, timeStart, timeStop), ImageFormat.Bmp);try{// create a media sample using the captured sample from abovemediaSampleFrame = sampleTarget.GetSample(1000);}catch (COMException cex){// if we have reached the end of stream we are finishedif (cex.ErrorCode == (int)ErrorCode.VFW_E_SAMPLE_REJECTED_EOS|| cex.ErrorCode == (int)ErrorCode.VFW_E_WRONG_STATE)break;else if (cex.ErrorCode == (int)ErrorCode.VFW_E_TIMEOUT)continue;elsethrow cex;}// loop on the state and pump messages for this example.// should not be needed if running from a Windows Forms application.if (convertCtrl.State == ConvertState.Running)Application.DoEvents();}// set the result_result = true;}catch (Exception){_result = false;}}static class LEAD_VARS{public const string MediaDir = @"C:\LEADTOOLS23\Media";}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
