Class WmfImage

Class WmfImage

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

Manipulate Microsoft Windows Metafile (WMF) images with our API, seamlesslyhandling both vector and bitmap data stored within variable-length records.Resize, rotate, and flip images with ease while setting custom image palettes.Convert WMF files to compressed WMZ formats or save them in raster image formatsfor versatile usage across platforms and applications.

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

Inheritance

object DisposableObject DataStreamSupporter Image VectorImage MetaImage WmfImage

Implements

IDisposable , IObjectWithBounds , IObjectWithSizeF

Inherited Members

MetaImage.GetUsedFonts() , MetaImage.GetMissedFonts() , MetaImage.ResizeCanvas(Rectangle) , MetaImage.GetCanNotSaveMessage(ImageOptionsBase) , MetaImage.SaveData(Stream) , 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.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()

Examples

The following example shows how to convert a wmz images to wmf fromat

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

The following example shows how to convert a wmf images to wmz fromat

string file = "castle.wmf";
   string baseFolder = System.IO.Path.Combine("D:", "Compressed");
   string inputFile = System.IO.Path.Combine(baseFolder, file);
   string outFile = inputFile + ".wmz";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFile))
   {
       Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions = new Aspose.Imaging.ImageOptions.WmfRasterizationOptions() { PageSize = image.Size };
       image.Save(outFile, new Aspose.Imaging.ImageOptions.WmfOptions() { VectorRasterizationOptions = vectorRasterizationOptions, Compress = true });
   }

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

string[] files =
   {
      "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 WMF image from a file and convert it to SVG using WmfRasterizationOptions.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Wmf.WmfImage wmfImage = (Aspose.Imaging.FileFormats.Wmf.WmfImage)Aspose.Imaging.Image.Load(dir + "test.wmf"))
   {
       Aspose.Imaging.ImageOptions.SvgOptions saveOptions = new Aspose.Imaging.ImageOptions.SvgOptions();
       saveOptions.TextAsShapes = true;
       Aspose.Imaging.ImageOptions.WmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.WmfRasterizationOptions();
       rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
       rasterizationOptions.PageSize = wmfImage.Size;
       rasterizationOptions.RenderMode = Aspose.Imaging.FileFormats.Wmf.WmfRenderMode.Auto;
       saveOptions.VectorRasterizationOptions = rasterizationOptions;
       wmfImage.Save(dir + "test.output.svg", saveOptions);
   }

Constructors

WmfImage()

Create a new instance of the Aspose.Imaging.FileFormats.Wmf.WmfImage class, initializing it forfurther manipulation and processing of Windows Metafile (WMF) image data. Thisconstructor provides a foundational object for working with WMF images, enablingseamless integration of WMF image handling capabilities into your application’sfunctionality.

public class WmfImage
   {
       [JsonConstructor]
       public WmfImage()
       {
       }
   }

WmfImage(int, int)

Instantiate a new instance of the Aspose.Imaging.FileFormats.Wmf.WmfImage class with customizablewidth and height parameters, facilitating the creation of blank WMF imagestailored to specific dimensions. Utilize this constructor to dynamically generateWMF images with precise dimensions, enabling flexible image creation andmanipulation within your application.

public WmfImage(int width, int height)
   {
   }

Parameters

width int

The width.

height int

The height.

Properties

BitsPerPixel

Retrieve the count of bits per pixel for the image, indicating the level of colordepth or granularity. Utilize this property to determine the image’s colorrepresentation and precision, facilitating compatibility checks and color-relatedprocessing within your application.

[JsonIgnore]
public override int BitsPerPixel
{
    get;
}

Property Value

int

Exceptions

NotImplementedException

FileFormat

Access the file format value associated with the image, providing informationabout the format in which the image is stored. Utilize this property to determinethe file format of the image, facilitating compatibility checks andformat-specific processing within your application.

public override FileFormat
    Get()
    {
        return this.FileFormat;
    }

Property Value

FileFormat

FrameBounds

Access the bounds of the frame, indicating its position and dimensions within theimage. Utilize this property to retrieve detailed information about the frame’sspatial location, enabling precise manipulation and rendering within your application.

public Rectangle FrameBounds
   {
      get;
   }

Property Value

Rectangle

HeightF

Access the image’s height, representing the number of pixels along its verticalaxis. Utilize this property to ascertain the image’s spatial dimensions and aspectratio, enabling accurate layout and rendering adjustments within your application.

public override float HeightF
   {
      get;
   }

Property Value

float

Exceptions

NotImplementedException

Inch

Access or modify the inch property, representing a unit of measurement typicallyused for specifying physical dimensions in print or display contexts. Utilize thisproperty to establish or retrieve inch values associated with the image,facilitating accurate representation of physical dimensions within your application.

public int Inch
   {
      get;
      set;
   }

Property Value

int

IsCached

Retrieve a boolean value indicating whether the object’s data is currently cached,eliminating the need for additional data reading operations. Utilize this propertyto optimize performance by determining if the object’s data is readily availablewithout the need for costly data retrieval processes within your application.

public override bool IsCached
   {
      get;
   }

Property Value

bool

Exceptions

NotImplementedException

WidthF

Access the width of the image, indicating the number of pixels along itshorizontal axis. Utilize this property to determine the image’s spatial dimensionsand aspect ratio, enabling precise layout and rendering adjustments within yourapplication.

public override float WidthF
   {
      get;
   }

Property Value

float

Exceptions

NotImplementedException

Methods

AddRecord(WmfObject)

Incorporate the specified record object into the image, enriching its content withadditional data or metadata. Utilize this method to seamlessly integrate recordobjects into the image, facilitating comprehensive data storage and organizationwithin your application.

public int AddRecord(WmfObject record)
{
}
The given code is already properly indented, spaced, and reads well. No modifications are needed to adhere to the rules provided.

Parameters

record WmfObject

The record.

Returns

int

Number of record.

CacheData()

Efficiently cache the data, eliminating the need for additional loading from theunderlying Aspose.Imaging.DataStreamSupporter.DataStreamContainer. Utilize thismethod to optimize performance and minimize resource usage within your applicationby storing and accessing local data cache.

public override void CacheData()
{
}

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();
       Console.WriteLine("The total number of records: {0}", wmfImage.Records.Count);
       var types = new Dictionary<Type, int>();
       foreach (Aspose.Imaging.FileFormats.Wmf.Objects.WmfObject obj in wmfImage.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);
       }
   }

Exceptions

NotImplementedException

GetOriginalOptions()

Gets the original image options.

public override ImageOptionsBase GetOriginalOptions()
{
}
In this case, the given code is already properly formatted according to standard C# conventions, so no changes were made.

Returns

ImageOptionsBase

The original image options.

GetPostScript()

Access the PostScript data associated with the image, providing detailedinformation about its structure or content. Utilize this method to retrievePostScript data for further analysis or processing within your application,enabling advanced functionality related to PostScript rendering or manipulation.

public string GetPostScript()
{
}

Returns

string

The post script

GetUsedFonts()

Retrieve the list of fonts used within the metafile, providing insight into thefont resources utilized in the image. Utilize this method to analyze font usageand ensure font availability for rendering or further processing within your application.

public override string[] GetUsedFonts()
{
    var usedFonts = new HashSet<string>();
    foreach (var node in Document.Range.ChildNodes)
    {
        if (node is TextNode textNode && textNode.Font != null)
            usedFonts.Add(textNode.Font.Name);
    }
    return usedFonts.ToArray();
}

Returns

string []

The font list

ResizeCanvas(Rectangle)

Resize the canvas of the image, adjusting its dimensions while retaining the imagecontent. Utilize this method to modify the size of the canvas without altering thecontent, facilitating layout adjustments and composition changes within yourapplication.

public override void ResizeCanvas(Rectangle newRectangle)
{
}

Parameters

newRectangle Rectangle

The new rectangle.

Exceptions

NotImplementedException

SetPalette(IColorPalette, bool)

Apply a specified palette to the image, enabling customization of colorrepresentation. Utilize this method to enhance visual rendering and achievespecific color effects within your application.

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 colorindexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have nocorresponding palette entries.

Exceptions

NotImplementedException

 English