Class EmfImage

Class EmfImage

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

The API for Enhanced Metafile Format (EMF) vector image format support isa comprehensive tool for processing graphical images in a device-independentmanner while preserving their original properties. Developed to maintainproportions, dimensions, colors, and other graphic attributes, it includesEMF Plus format support and features for cropping regions, resizing canvasand images, rotating, flipping, setting image palettes, exporting and importingto APS device context, compressing and converting EMF to other formats, ensuringversatile manipulation and seamless integration of EMF images across applications.

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

Inheritance

object DisposableObject DataStreamSupporter Image VectorImage MetaImage EmfImage

Implements

IDisposable , IObjectWithBounds , IObjectWithSizeF

Inherited Members

MetaImage.GetUsedFonts() , MetaImage.GetMissedFonts() , MetaImage.ResizeCanvas(Rectangle) , MetaImage.Records , 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.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.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.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.Disposed , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

The following example shows how to convert a emz images to emf fromat

string file = "example.emz";
   string baseFolder = System.IO.Path.Combine("D:", "Compressed");
   string inputFile = System.IO.Path.Combine(baseFolder, file);
   string outFile = inputFile + ".emf";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFile))
   {
       Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions
       {
           PageSize = image.Size
       };
       image.Save(outFile, new Aspose.Imaging.ImageOptions.EmfOptions
       {
           VectorRasterizationOptions = vectorRasterizationOptions
       });
   }

The following example shows how to convert a emf images to emz fromat

string file = "input.emf";
   string baseFolder = System.IO.Path.Combine("D:", "Compressed");
   string inputFile = System.IO.Path.Combine(baseFolder, file);
   string outFile = inputFile + ".emz";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFile))
   {
       Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions() { PageSize = image.Size };
       image.Save(outFile, new Aspose.Imaging.ImageOptions.EmfOptions() { VectorRasterizationOptions = vectorRasterizationOptions, Compress = true });
   }

The following example shows how to convert a compressed images (.emz,.wmz, *.svgz) to raster fromat

string[] files = new[] { "example.emz", "example.wmz", "example.svgz" };
   string baseFolder = System.IO.Path.Combine("D:", "Compressed");
   foreach (var file in files)
   {
       string inputFile = System.IO.Path.Combine(baseFolder, file);
       string outFile = inputFile + ".png";
       using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFile))
       {
           Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Color.White, image.Width, image.Height });
           image.Save(outFile, new Aspose.Imaging.ImageOptions.PngOptions() { VectorRasterizationOptions = vectorRasterizationOptions });
       }
   }

This example shows how to load a EMF image from a file and convert it to SVG using EmfRasterizationOptions.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(dir + "test.emf"))
   {
      Aspose.Imaging.ImageOptions.SvgOptions saveOptions = new Aspose.Imaging.ImageOptions.SvgOptions();
      saveOptions.TextAsShapes = true;
      Aspose.Imaging.ImageOptions.EmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions();
      rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
      rasterizationOptions.PageSize = emfImage.Size;
      rasterizationOptions.RenderMode = Aspose.Imaging.FileFormats.Emf.EmfRenderMode.Auto;
      rasterizationOptions.BorderX = 50;
      rasterizationOptions.BorderY = 50;
      saveOptions.VectorRasterizationOptions = rasterizationOptions;
      emfImage.Save(dir + "test.output.svg", saveOptions);
   }

Constructors

EmfImage()

Start working with EMF images by initializing a new instance of theAspose.Imaging.FileFormats.Emf.EmfImage class. Ideal for quickly incorporating EMF images intoyour projects with ease and efficiency.

[JsonConstructor]
   public EmfImage()
   {
   }

EmfImage(int, int)

Create a new instance of the Aspose.Imaging.FileFormats.Emf.EmfImage class by specifying the widthand height parameters. This constructor simplifies the process of initializingEMF images with specific dimensions, enhancing the efficiency of your developmentworkflow.

public EmfImage(int width, int height)
   {
   }

Parameters

width int

The width.

height int

The height.

Properties

BitsPerPixel

Retrieve the bit-per-pixel count specific to raster images, as this parameterdoesn’t apply to vector images. Quickly ascertain the pixel depth of rasterimages for precise analysis and manipulation, ensuring accurate handlingof image data.

public override int BitsPerPixel
    {
        get;
    }

Property Value

int

Exceptions

NotImplementedException

Invalid for vector images.

FileFormat

Access the file format value associated with the object. Easily determine theformat of the file associated with the object for streamlined processing andcompatibility checks. Simplify your workflow by retrieving the file formatinformation with ease.

public override FileFormat GetFileFormat()
{
}

Property Value

FileFormat

Header

Retrieve or modify the EMF metafile header record with this property. Ideal formanaging metafile data efficiently within your application. Improve your workflowwith streamlined access to metafile header information.

public EmfMetafileHeader Header
   {
      get;
      set;
   }

Property Value

EmfMetafileHeader

HeightF

Retrieve the image’s height, facilitating accurate rendering and layout adjustments.Accessing the height property ensures compatibility and seamless integration acrossdifferent platforms and applications.

public override float HeightF
   {
      get;
   }

Property Value

float

IsCached

Access a value indicating whether the object’s data is currently cached,eliminating the need for additional data reading. Enhance efficiency by quicklydetermining if cached data is available for immediate access. Optimize yourworkflow with streamlined data retrieval processes.

public override bool IsCached
   {
      get;
   }

Property Value

bool

Records

Retrieve or modify the records associated with the object. Efficiently access andmanage the collection of records for enhanced data manipulation and processing.Optimize your workflow by seamlessly interacting with the object’s records.

public override MetaObjectList Records
{
    get;
    set;
}

Property Value

MetaObjectList

WidthF

Access to the width of the image, providing essential information for preciserendering and processing. Quickly retrieve the image’s width to ensure compatibilityand proper layout within various applications and platforms.

public override float WidthF
    {
        get;
    }

Property Value

float

Methods

CacheData()

Efficiently cache data and prevent redundant loading from the underlyingAspose.Imaging.DataStreamSupporter.DataStreamContainer with this method. Enhanceperformance and streamline data access in your application, optimizing resourceutilization for improved responsiveness.

public override void CacheData()
   {
   }

Examples

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(' ', 36 - objectType.Length);
           Console.WriteLine("{0}:{1}", entry.Key.Name, alignmentGap, entry.Value);
       }
   }

GetOriginalOptions()

Gets the original image options.

public override ImageOptionsBase GetOriginalOptions()
{
}

Returns

ImageOptionsBase

The original image options.

GetUsedFonts()

Retrieve the list of fonts utilized within the metafile with this method. Gaininsights into font usage, facilitating efficient management and optimization of fontresources for enhanced rendering and display fidelity.

public override string[] GetUsedFonts()
{
}
In your given code, it seems already well-formatted according to standard C# conventions. However, if you have more lines of code within the method body, they should be indented properly like this:
public override string[] GetUsedFonts()
{
    List<string> fonts = new List<string>();
    return fonts.ToArray();
}

Returns

string []

The font list

ResizeCanvas(Rectangle)

Resize the canvas with ease using this function. Perfect for adjusting the overalldimensions of the image without altering its content. Enhance presentation andprepare images for various display sizes effortlessly.

public override void ResizeCanvas(Rectangle newRectangle)
   {
   }

Parameters

newRectangle Rectangle

The new rectangle.

SetPalette(IColorPalette, bool)

Sets the image palette.

public override void
      SetPalette(IColorPalette palette, bool updateColors)
   {
   }

Parameters

palette IColorPalette

The palette to set.

updateColors bool

if set to ’true’ colors will be updated according to the new palette; otherwise color indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no corresponding palette entries.

Exceptions

NotImplementedException

 English