Class MetaImage

Class MetaImage

Namespace: Aspose.Imaging.FileFormats.Emf
Assembly: Aspose.Imaging.dll (25.7.0)

Base class for Meta object classes

[JsonObject(MemberSerialization.OptIn)]
   public abstract class MetaImage : VectorImage, IDisposable, IObjectWithBounds, IObjectWithSizeF
   {
   }

Inheritance

object DisposableObject DataStreamSupporter Image VectorImage MetaImage

Derived

EmfImage , WmfImage

Implements

IDisposable , IObjectWithBounds , IObjectWithSizeF

Inherited Members

VectorImage.GetDefaultOptions(object[]) , VectorImage.GetEmbeddedImages() , VectorImage.RemoveBackground() , VectorImage.RemoveBackground(RemoveBackgroundSettings) , VectorImage.Resize(int, int, ResizeType) , VectorImage.Resize(int, int, ImageResizeSettings) , VectorImage.RotateFlip(RotateFlipType) , VectorImage.Crop(Rectangle) , VectorImage.Rotate(float) , VectorImage.Modify(RectangleF, float, float, float) , VectorImage.ReleaseManagedResources() , VectorImage.SizeF , VectorImage.WidthF , VectorImage.HeightF , VectorImage.Width , VectorImage.Height , Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.UpdateContainer(Image) , Image.GetCanNotSaveMessage(ImageOptionsBase) , Image.GetFitRectangle(Rectangle) , Image.GetImage2Export(ImageOptionsBase, Rectangle, IImageExporter) , Image.GetFitRectangle(Rectangle, int[]) , Image.OnPaletteChanged(IColorPalette, IColorPalette) , Image.OnPaletteChanging(IColorPalette, IColorPalette) , Image.ReleaseManagedResources() , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.timeout , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.SaveData(Stream) , DataStreamSupporter.ReleaseManagedResources() , DataStreamSupporter.OnDataStreamContainerChanging(StreamContainer) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Constructors

MetaImage()

Initializes a new instance of the Aspose.Imaging.FileFormats.Emf.MetaImage.

public MetaImage()
   {
   }

Properties

Records

Gets or sets the records.

public virtual MetaObjectList Records
{
    get;
    set;
}

Property Value

MetaObjectList

Examples

This example shows how to load a WMF image from a file and list all of its records.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Wmf.WmfImage wmfImage = (Aspose.Imaging.FileFormats.Wmf.WmfImage)Aspose.Imaging.Image.Load(dir + "test.wmf"))
   {
       wmfImage.CacheData();
       System.Console.WriteLine("The total number of records: {0}", wmfImage.Records.Count);
       var types = new System.Collections.Generic.Dictionary<System.Type, int>();
       foreach (Aspose.Imaging.FileFormats.Wmf.Objects.WmfObject obj in wmfImage.Records)
       {
           System.Type objType = obj.GetType();
           if (!types.ContainsKey(objType))
           {
               types.Add(objType, 1);
           }
           else
           {
               types[objType]++;
           }
       }
       System.Console.WriteLine("Record Type                              Count");
       System.Console.WriteLine("----------------------------------------------");
       foreach (System.Collections.Generic.KeyValuePair<System.Type, int> entry in types)
       {
           string objectType = entry.Key.Name;
           string alignmentGap = new string(' ', 40 - objectType.Length);
           System.Console.WriteLine("{0}:{1}{2}", entry.Key.Name, alignmentGap, entry.Value);
       }
   }

This example shows how to load a EMF image from a file and list all of its records.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(dir + "test.emf"))
   {
       emfImage.CacheData();
       Console.WriteLine("The total number of records: {0}", emfImage.Records.Count);
       var types = new Dictionary<Type, int>();
       foreach (var obj in emfImage.Records)
       {
           Type objType = obj.GetType();
           if (!types.ContainsKey(objType))
           {
               types.Add(objType, 1);
           }
           else
           {
               types[objType]++;
           }
       }
       Console.WriteLine("Record Type                              Count");
       Console.WriteLine("----------------------------------------------");
       foreach (KeyValuePair<Type, int> entry in types)
       {
           string objectType = entry.Key.Name;
           string alignmentGap = new string(' ', 40 - objectType.Length);
           Console.WriteLine("{0}:{1}{2}", entry.Key.Name, alignmentGap, entry.Value);
       }
   }

Methods

GetCanNotSaveMessage(ImageOptionsBase)

Gets the can not save message.

protected override string GetCanNotSaveMessage(ImageOptionsBase optionsBase)
   {
      return string.Format("Cannot save image with format '{0}'. The specified ImageOptionsBase object does not support saving in this format.", optionsBase.Format);
   }

Parameters

optionsBase ImageOptionsBase

The image options.

Returns

string

The can not save message.

GetMissedFonts()

Returns the list of fonts which used inside metafile but not found.

public string[] GetMissedFonts()
{
    var missedFonts = new List<string>();
    return missedFonts.ToArray();
}

Returns

string []

The font list

Examples

The following example shows how to print information about used and missed fonts in WMF/EMF images.

string dir = "c:\\aspose.imaging\\net\\issues\\3544";
   string[] fontDirectories = Aspose.Imaging.FontSettings.GetFontsFolders();
   Aspose.Imaging.FontSettings.SetFontsFolder("empty");
   string[] files = new string[]
   {
       "TestWmfText.wmf",
       "TestEmfFonts.emf",
       "TestEmfPlusFonts.emf",
   };
   try
   {
      foreach (string file in files)
      {
          System.Console.WriteLine("========== {0} ==========", file);
          using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(System.IO.Path.Combine(dir, file)))
          {
              string[] used = image.GetUsedFonts();
              foreach (string it in used)
              {
                  System.Console.WriteLine("Used font: " + it);
              }
              string[] missed = image.GetMissedFonts();
              foreach (string it in missed)
              {
                  System.Console.WriteLine("Missed font: " + it);
              }
              int ui = 0, mi = 0;
              foreach (string it in used)
              {
                  if (it.Contains("Times"))
                  {
                      ui++;
                      continue;
                  }
                  if (used[ui] != missed[mi])
                  {
                      throw new System.Exception("Font lists must be equal!");
                  }
                  ui++; mi++;
              }
          }
      }
   }
   finally
   {
       Aspose.Imaging.FontSettings.SetFontsFolders(fontDirectories, true);
   }

GetUsedFonts()

Returns the list of font which used inside metafile.

public abstract string[] GetUsedFonts()
{
}

Returns

string []

The font list

Examples

The following example shows how to print information about used and missed fonts in WMF/EMF images.

string dir = "c:\\aspose.imaging\\net\\issues\\3544";
    string[] fontDirectories = Aspose.Imaging.FontSettings.GetFontsFolders();
    Aspose.Imaging.FontSettings.SetFontsFolder("empty");
    string[] files = new string[]
    {
        "TestWmfText.wmf",
        "TestEmfFonts.emf",
        "TestEmfPlusFonts.emf",
    };
    try
    {
        foreach (string file in files)
        {
            System.Console.WriteLine("========== {0} ==========", file);
            using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(System.IO.Path.Combine(dir, file)))
            {
                string[] used = image.GetUsedFonts();
                foreach (string it in used)
                {
                    System.Console.WriteLine("Used font: " + it);
                }
                string[] missed = image.GetMissedFonts();
                foreach (string it in missed)
                {
                    System.Console.WriteLine("Missed font: " + it);
                }
                int ui = 0, mi = 0;
                foreach (string it in used)
                {
                    if (it.Contains("Times"))
                    {
                        ui++;
                        continue;
                    }
                    if (used[ui] != missed[mi])
                    {
                        throw new System.Exception("Font lists must be equal!");
                    }
                    ui++; mi++;
                }
            }
        }
    }
    finally
    {
        Aspose.Imaging.FontSettings.SetFontsFolders(fontDirectories, true);
    }

ResizeCanvas(Rectangle)

Resizes the canvas.

public abstract void ResizeCanvas(Rectangle newRectangle)
    {
    }

Parameters

newRectangle Rectangle

The new rectangle.

Examples

The following example shows how to add a border with the specified margins around a metafile (WMF and EMF).

int borderLeft = 50;
   int borderTop = 50;
   int borderRight = 50;
   int borderBottom = 50;
   string dir = "c:\\aspose.imaging\\issues\\net\\3280\\";
   string[] fileNames = new[] { "image1.emf", "image2.wmf" };
   foreach (string fileName in fileNames)
   {
       string inputFilePath = dir + fileName;
       string outputFilePath = dir + "AddBorder_" + fileName;
       using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(inputFilePath))
       {
           image.ResizeCanvas(new Aspose.Imaging.Rectangle(-borderLeft, -borderTop, image.Width + borderLeft + borderRight, image.Height + borderTop + borderBottom));
           image.Save(outputFilePath);
       }
   }

SaveData(Stream)

Saves the data to specified stream'.

protected override sealed void SaveData(Stream stream)
   {
   }

Parameters

stream Stream

The stream.

 English