Class EmfImage
Namespace: Aspose.Imaging.FileFormats.Emf
Assembly: Aspose.Imaging.dll (25.2.0)
The API for Enhanced Metafile Format (EMF) vector image format support is a comprehensive tool for processing graphical images in a device-independent manner while preserving their original properties. Developed to maintain proportions, dimensions, colors, and other graphic attributes, it includes EMF Plus format support and features for cropping regions, resizing canvas and images, rotating, flipping, setting image palettes, exporting and importing to APS device context, compressing and converting EMF to other formats, ensuring versatile 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.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```csharp [C#]
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```csharp
[C#]
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```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 EMF image from a file and convert it to SVG using EmfRasterizationOptions.```csharp
[C#]
string dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including EMF.
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();
// Text will be converted to shapes.
saveOptions.TextAsShapes = true;
Aspose.Imaging.ImageOptions.EmfRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions();
// The background color of the drawing surface.
rasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
// The page size.
rasterizationOptions.PageSize = emfImage.Size;
// If embedded emf exists, then render emf; otherwise render wmf.
rasterizationOptions.RenderMode = Aspose.Imaging.FileFormats.Emf.EmfRenderMode.Auto;
// Set the horizontal margin
rasterizationOptions.BorderX = 50;
// Set the vertical margin
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 the Aspose.Imaging.FileFormats.Emf.EmfImage class. Ideal for quickly incorporating EMF images into your 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 width and height parameters. This constructor simplifies the process of initializing EMF images with specific dimensions, enhancing the efficiency of your development workflow.
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 parameter doesn’t apply to vector images. Quickly ascertain the pixel depth of raster images for precise analysis and manipulation, ensuring accurate handling of image data.
public override int BitsPerPixel { get; }
Property Value
Exceptions
Invalid for vector images.
FileFormat
Access the file format value associated with the object. Easily determine the format of the file associated with the object for streamlined processing and compatibility checks. Simplify your workflow by retrieving the file format information with ease.
public override FileFormat FileFormat { get; }
Property Value
Header
Retrieve or modify the EMF metafile header record with this property. Ideal for managing metafile data efficiently within your application. Improve your workflow with streamlined access to metafile header information.
public EmfMetafileHeader Header { get; set; }
Property Value
HeightF
Retrieve the image’s height, facilitating accurate rendering and layout adjustments. Accessing the height property ensures compatibility and seamless integration across different platforms and applications.
public override float HeightF { get; }
Property Value
IsCached
Access a value indicating whether the object’s data is currently cached, eliminating the need for additional data reading. Enhance efficiency by quickly determining if cached data is available for immediate access. Optimize your workflow with streamlined data retrieval processes.
public override bool IsCached { get; }
Property Value
Records
Retrieve or modify the records associated with the object. Efficiently access and manage 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
WidthF
Access to the width of the image, providing essential information for precise rendering and processing. Quickly retrieve the image’s width to ensure compatibility and proper layout within various applications and platforms.
public override float WidthF { get; }
Property Value
Methods
CacheData()
Efficiently cache data and prevent redundant loading from the underlying Aspose.Imaging.DataStreamSupporter.DataStreamContainer with this method. Enhance performance and streamline data access in your application, optimizing resource utilization 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.```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.Emf.EmfImage emfImage = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(dir + "test.emf"))
{
// Cache data to load all records.
emfImage.CacheData();
System.Console.WriteLine("The total number of records: {0}", emfImage.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.Emf.Emf.Records.EmfRecord obj in emfImage.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: 1188
//Record Type Count
//----------------------------------------------
//EmfMetafileHeader: 1
//EmfSetBkMode: 1
//EmfSetTextAlign: 1
//EmfSetRop2: 1
//EmfSetWorldTransform: 1
//EmfExtSelectClipRgn: 1
//EmfCreateBrushIndirect: 113
//EmfSelectObject: 240
//EmfCreatePen: 116
//EmfSetPolyFillMode: 1
//EmfBeginPath: 120
//EmfMoveToEx: 122
//EmfPolyBezierTo16: 36
//EmfLineTo: 172
//EmfCloseFigure: 14
//EmfEndPath: 120
//EmfStrokeAndFillPath: 113
//EmfStrokePath: 7
//EmfSetTextColor: 2
//EmfExtCreateFontIndirectW: 2
//EmfExtTextOutW: 2
//EmfStretchBlt: 1
//EmfEof: 1</system.type,></system.type,></system.type,>
### <a id="Aspose_Imaging_FileFormats_Emf_EmfImage_GetDefaultOptions_System_Object___"></a> GetDefaultOptions\(object\[\]\)
Retrieve the default options for your image effortlessly. With this feature, you
can quickly access the preset configurations, ensuring seamless integration and
optimal performance for your projects. Ideal for streamlining your workflow and
achieving consistent results across your images.
```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.
GetUsedFonts()
Retrieve the list of fonts utilized within the metafile with this method. Gain insights into font usage, facilitating efficient management and optimization of font resources for enhanced rendering and display fidelity.
public override string[] GetUsedFonts()
Returns
string[]
The font list
ResizeCanvas(Rectangle)
Resize the canvas with ease using this function. Perfect for adjusting the overall dimensions of the image without altering its content. Enhance presentation and prepare 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.