Class WmfImage
Namespace: Aspose.Imaging.FileFormats.Wmf
Assembly: Aspose.Imaging.dll (25.2.0)
Manipulate Microsoft Windows Metafile (WMF) images with our API, seamlessly handling 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 formats for 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.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.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```csharp [C#]
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```csharp
[C#]
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```csharp [C#]
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 WMF image from a file and convert it to SVG using WmfRasterizationOptions.```csharp
[C#]
string dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including WMF.
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();
// Text will be converted to shapes.
saveOptions.TextAsShapes = true;
Aspose.Imaging.ImageOptions.WmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.WmfRasterizationOptions();
// The background color of the drawing surface.
rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
// The page size.
rasterizationOptions.PageSize = wmfImage.Size;
// If embedded emf exists, then render emf; otherwise render wmf.
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 for further manipulation and processing of Windows Metafile (WMF) image data. This constructor provides a foundational object for working with WMF images, enabling seamless integration of WMF image handling capabilities into your application’s functionality.
[JsonConstructor]
public WmfImage()
WmfImage(int, int)
Instantiate a new instance of the Aspose.Imaging.FileFormats.Wmf.WmfImage class with customizable width and height parameters, facilitating the creation of blank WMF images tailored to specific dimensions. Utilize this constructor to dynamically generate WMF images with precise dimensions, enabling flexible image creation and manipulation 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 color depth or granularity. Utilize this property to determine the image’s color representation and precision, facilitating compatibility checks and color-related processing within your application.
[JsonIgnore]
public override int BitsPerPixel { get; }
Property Value
Exceptions
FileFormat
Access the file format value associated with the image, providing information about the format in which the image is stored. Utilize this property to determine the file format of the image, facilitating compatibility checks and format-specific processing within your application.
public override FileFormat FileFormat { get; }
Property Value
FrameBounds
Access the bounds of the frame, indicating its position and dimensions within the image. Utilize this property to retrieve detailed information about the frame’s spatial location, enabling precise manipulation and rendering within your application.
public Rectangle FrameBounds { get; }
Property Value
HeightF
Access the image’s height, representing the number of pixels along its vertical axis. Utilize this property to ascertain the image’s spatial dimensions and aspect ratio, enabling accurate layout and rendering adjustments within your application.
public override float HeightF { get; }
Property Value
Exceptions
Inch
Access or modify the inch property, representing a unit of measurement typically used for specifying physical dimensions in print or display contexts. Utilize this property 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
IsCached
Retrieve a boolean value indicating whether the object’s data is currently cached, eliminating the need for additional data reading operations. Utilize this property to optimize performance by determining if the object’s data is readily available without the need for costly data retrieval processes within your application.
public override bool IsCached { get; }
Property Value
Exceptions
WidthF
Access the width of the image, indicating the number of pixels along its horizontal axis. Utilize this property to determine the image’s spatial dimensions and aspect ratio, enabling precise layout and rendering adjustments within your application.
public override float WidthF { get; }
Property Value
Exceptions
Methods
AddRecord(WmfObject)
Incorporate the specified record object into the image, enriching its content with additional data or metadata. Utilize this method to seamlessly integrate record objects into the image, facilitating comprehensive data storage and organization within your application.
public int AddRecord(WmfObject record)
Parameters
record
WmfObject
The record.
Returns
Number of record.
CacheData()
Efficiently cache the data, eliminating the need for additional loading from the underlying Aspose.Imaging.DataStreamSupporter.DataStreamContainer. Utilize this method to optimize performance and minimize resource usage within your application by 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.```csharp [C#]
string dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including WMF.
using (Aspose.Imaging.FileFormats.Wmf.WmfImage wmfImage = (Aspose.Imaging.FileFormats.Wmf.WmfImage)Aspose.Imaging.Image.Load(dir + "test.wmf"))
{
// Cache data to load all records.
wmfImage.CacheData();
System.Console.WriteLine("The total number of records: {0}", wmfImage.Records.Count);
// The key is a record type, the value is number of records of that type in the WMF image.
System.Collections.Generic.Dictionary<system.type, int=""> types =
new System.Collections.Generic.Dictionary<system.type, int="">();
// Gather statistics
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]++;
}
}
// Print statistics
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);
}
}
//The output may look like this:
//The total number of records: 613
//Record Type Count
//----------------------------------------------
//WmfSetBkMode: 1
//WmfSetTextAlign: 1
//WmfSetRop2: 1
//WmfSetWindowOrg: 1
//WmfSetWindowExt: 1
//WmfCreateBrushInDirect: 119
//WmfSelectObject: 240
//WmfCreatePenInDirect: 119
//WmfSetPolyFillMode: 1
//WmfPolyPolygon: 114
//WmfPolyLine: 7
//WmfSetTextColor: 2
//WmfCreateFontInDirect: 2
//WmfExtTextOut: 2
//WmfDibStrechBlt: 1
//WmfEof: 1</system.type,></system.type,></system.type,>
#### Exceptions
[NotImplementedException](https://learn.microsoft.com/dotnet/api/system.notimplementedexception)
### <a id="Aspose_Imaging_FileFormats_Wmf_WmfImage_GetDefaultOptions_System_Object___"></a> GetDefaultOptions\(object\[\]\)
Retrieve the default options associated with the image, providing access to
predefined settings or configurations. Utilize this method to access default
settings for image processing operations, facilitating consistency and convenience
within your application's functionality.
```csharp
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object[]
The arguments.
Returns
Default options
GetOriginalOptions()
Gets the original image options.
public override ImageOptionsBase GetOriginalOptions()
Returns
The original image options.
GetPostScript()
Access the PostScript data associated with the image, providing detailed information about its structure or content. Utilize this method to retrieve PostScript data for further analysis or processing within your application, enabling advanced functionality related to PostScript rendering or manipulation.
public string GetPostScript()
Returns
The post script
GetUsedFonts()
Retrieve the list of fonts used within the metafile, providing insight into the font resources utilized in the image. Utilize this method to analyze font usage and ensure font availability for rendering or further processing within your application.
public override string[] GetUsedFonts()
Returns
string[]
The font list
ResizeCanvas(Rectangle)
Resize the canvas of the image, adjusting its dimensions while retaining the image content. Utilize this method to modify the size of the canvas without altering the content, facilitating layout adjustments and composition changes within your application.
public override void ResizeCanvas(Rectangle newRectangle)
Parameters
newRectangle
Rectangle
The new rectangle.
Exceptions
SetPalette(IColorPalette, bool)
Apply a specified palette to the image, enabling customization of color representation. Utilize this method to enhance visual rendering and achieve specific 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 color
indexes remain unchanged. Note that unchanged indexes may crash the image on loading if some indexes have no
corresponding palette entries.