Format Property

Summary
Gets the direct reference to the format buffer.
Syntax
C#
C++/CLI
public object Format { get; } 
public: 
property Object^ Format { 
   Object^ get(); 
} 

Property Value

An object representing the format buffer.

Remarks

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.

Example
C#
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
 
public bool _result = false; 
public ConvertCtrlForm _form = new ConvertCtrlForm(); 
 
public void FormatExample() 
{ 
   // reference the convert control 
   ConvertCtrl convertCtrl = _form.ConvertCtrl; 
 
   // input file and output files 
   string 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 files 
      convertCtrl.SourceFile = inFile; 
 
      // set the preview 
      convertCtrl.Preview = true; 
 
      // create a new sample target 
      SampleTarget sampleTarget = new SampleTarget(); 
 
      // set the target media type for the video stream 
      MediaType targetMediaType = new MediaType(); 
      targetMediaType.Type = Constants.MEDIATYPE_Video; 
      targetMediaType.SubType = Constants.MEDIASUBTYPE_RGB24; 
 
      // set the sample target's accepted media type 
      sampleTarget.SetAcceptedMediaType(targetMediaType); 
 
      // assign the sample target to the capture control 
      convertCtrl.TargetObject = sampleTarget; 
      convertCtrl.TargetFormat = TargetFormatType.StillImage; 
 
      // run the convert 
      convertCtrl.StartConvert(); 
 
      // get and process each meda sample delivered to the convertCtrl 
      MediaSample mediaSampleFrame = sampleTarget.GetSample(1000); 
      while (mediaSampleFrame != null) 
      { 
         // demonstrates copying a MediaType's object properties 
         MediaType mediaTypeCopy = new MediaType(); 
         using (MediaType mediaTypeSample = sampleTarget.GetConnectedMediaType()) 
         { 
            int mediaTypeFormatSize = mediaTypeSample.FormatSize; 
            if (mediaTypeFormatSize > 0) 
               mediaTypeCopy.SetFormatData(mediaTypeFormatSize, mediaTypeSample.Format); 
            else 
               mediaTypeCopy.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 header 
         VideoInfoHeader 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 it  
         Bitmap 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 buffer  
         bitmap.RotateFlip(RotateFlipType.Rotate180FlipX); 
 
         // get media time which correspond to frame numbers in video 
         mediaSampleFrame.GetTime(out long timeStart, out long timeStop); 
 
         // save the image  
         bitmap.Save(string.Format("{0}_{1}-{2}.bmp", outFilePfx, timeStart, timeStop), ImageFormat.Bmp); 
 
         try 
         { 
            // create a media sample using the captured sample from above  
            mediaSampleFrame = sampleTarget.GetSample(1000); 
         } 
         catch (COMException cex) 
         { 
            // if we have reached the end of stream we are finished 
            if (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; 
            else 
               throw 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"; 
} 
Requirements

Target Platforms

See Also

Reference

MediaType Class

MediaType Members

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Multimedia Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.