EmfImage Class
EMF file format image.
Inheritance Hierarchy

Namespace: Aspose.Imaging.FileFormats.Emf
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 21.04
Syntax
public sealed class EmfImage : MetaImage

The EmfImage type exposes the following members.

Constructors
  NameDescription
Public methodEmfImage
Initializes a new instance of the EmfImage class.
Public methodEmfImage(Int32, Int32)
Initializes a new instance of the EmfImage class.
Properties
  NameDescription
Public propertyAutoAdjustPalette
Gets or sets a value indicating whether automatic adjust palette.
(Inherited from Image.)
Public propertyBackgroundColor
Gets or sets a value for the background color.
(Inherited from Image.)
Public propertyBitsPerPixel
Gets the image bits per pixel count this parameter is not applicable to vector images
(Overrides ImageBitsPerPixel.)
Public propertyBounds
Gets the image bounds.
(Inherited from Image.)
Public propertyBufferSizeHint
Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
(Inherited from Image.)
Public propertyContainer
Gets the Image container.
(Inherited from Image.)
Public propertyDataStreamContainer
Gets the object's data stream.
(Inherited from DataStreamSupporter.)
Public propertyDisposed
Gets a value indicating whether this instance is disposed.
(Inherited from DisposableObject.)
Public propertyFileFormat
Gets a value of file format
(Overrides ImageFileFormat.)
Public propertyHasBackgroundColor
Gets or sets a value indicating whether image has background color.
(Inherited from Image.)
Public propertyHeader
Gets or sets the header record
Public propertyHeight
Gets the image height.
(Overrides VectorImageHeight.)
Public propertyHeightF
Gets the object height, in inches.
(Inherited from VectorImage.)
Public propertyInterruptMonitor
Gets or sets the interrupt monitor.
(Inherited from Image.)
Public propertyIsCached
Gets a value indicating whether object's data is cached currently and no data reading is required.
(Overrides DataStreamSupporterIsCached.)
Public propertyPalette
Gets or sets the color palette. The color palette is not used when pixels are represented directly.
(Inherited from Image.)
Public propertyRecords
Gets or sets the records.
(Overrides MetaImageRecords.)
Public propertyCode exampleSize
Gets the image size.
(Inherited from Image.)
Public propertySizeF
Gets the object size, in inches.
(Inherited from VectorImage.)
Public propertyCode exampleUsePalette
Gets a value indicating whether the image palette is used.
(Inherited from Image.)
Public propertyWidth
Gets the image width.
(Overrides VectorImageWidth.)
Public propertyWidthF
Gets the object width, in inches.
(Inherited from VectorImage.)
Methods
  NameDescription
Public methodCode exampleCacheData
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamContainer.
(Overrides DataStreamSupporterCacheData.)
Public methodCode exampleCanSave
Determines whether image can be saved to the specified file format represented by the passed save options.
(Inherited from Image.)
Public methodCrop(Rectangle)
Crops the specified rectangle.
(Overrides MetaImageCrop(Rectangle).)
Public methodCrop(Int32, Int32, Int32, Int32)
Crop image with shifts.
(Inherited from MetaImage.)
Public methodCode exampleDispose
Disposes the current instance.
(Inherited from DisposableObject.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetDefaultOptions
Gets the default options.
(Overrides ImageGetDefaultOptions(Object).)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodCode exampleGetMissedFonts
Returns the list of fonts which used inside metafile but not found.
(Inherited from MetaImage.)
Public methodGetOriginalOptions
Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save(String) method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save(String, ImageOptionsBase) method as the second parameter.
(Inherited from Image.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodGetUsedFonts
Returns the list of font which used inside metafile.
(Overrides MetaImageGetUsedFonts.)
Public methodCode exampleResize(Int32, Int32)
Resizes the image. The default LeftTopToLeftTop is used.
(Inherited from Image.)
Public methodResize(Int32, Int32, ImageResizeSettings)
Resizes the image.
(Overrides ImageResize(Int32, Int32, ImageResizeSettings).)
Public methodResize(Int32, Int32, ResizeType)
Resizes the image.
(Overrides ImageResize(Int32, Int32, ResizeType).)
Public methodResizeCanvas
Resizes the canvas.
(Overrides MetaImageResizeCanvas(Rectangle).)
Public methodResizeHeightProportionally(Int32)
Resizes the height proportionally.
(Inherited from Image.)
Public methodResizeHeightProportionally(Int32, ImageResizeSettings)
Resizes the height proportionally.
(Inherited from Image.)
Public methodCode exampleResizeHeightProportionally(Int32, ResizeType)
Resizes the height proportionally.
(Inherited from Image.)
Public methodResizeWidthProportionally(Int32)
Resizes the width proportionally.
(Inherited from Image.)
Public methodResizeWidthProportionally(Int32, ImageResizeSettings)
Resizes the width proportionally.
(Inherited from Image.)
Public methodCode exampleResizeWidthProportionally(Int32, ResizeType)
Resizes the width proportionally.
(Inherited from Image.)
Public methodRotateFlip
Rotates, flips, or rotates and flips the image.
(Overrides ImageRotateFlip(RotateFlipType).)
Public methodCode exampleSave
Saves the image data to the underlying stream.
(Inherited from Image.)
Public methodSave(Stream)
Saves the object's data to the specified stream.
(Inherited from DataStreamSupporter.)
Public methodSave(String)
Saves the object's data to the specified file location.
(Inherited from DataStreamSupporter.)
Public methodSave(String, Boolean)
Saves the object's data to the specified file location.
(Inherited from DataStreamSupporter.)
Public methodCode exampleSave(Stream, ImageOptionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
(Inherited from Image.)
Public methodCode exampleSave(String, ImageOptionsBase)
Saves the object's data to the specified file location in the specified file format according to save options.
(Inherited from Image.)
Public methodCode exampleSave(Stream, ImageOptionsBase, Rectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
(Inherited from Image.)
Public methodCode exampleSave(String, ImageOptionsBase, Rectangle)
Saves the object's data to the specified file location in the specified file format according to save options.
(Inherited from Image.)
Public methodSetPalette
Sets the image palette.
(Overrides ImageSetPalette(IColorPalette, Boolean).)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Examples
The following example shows how to convert a emz images to emf fromat
[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});
}
Examples
The following example shows how to convert a emf images to emz fromat
[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});
}
Examples
The following example shows how to convert a compressed images (*.emz,*.wmz, *.svgz) to raster fromat
[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});
    }
}
Examples
This example shows how to load a EMF image from a file and convert it to SVG using EmfRasterizationOptions.
[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);
}
See Also