EmfImage

EmfImage class

EMF file format image.

public sealed class EmfImage : MetaImage

Constructors

Name Description
EmfImage() Initializes a new instance of the EmfImage class.
EmfImage(int, int) Initializes a new instance of the EmfImage class.

Properties

Name Description
AutoAdjustPalette { get; set; } Gets or sets a value indicating whether automatic adjust palette.
virtual BackgroundColor { get; set; } Gets or sets a value for the background color.
override BitsPerPixel { get; } Gets the image bits per pixel count this parameter is not applicable to vector images
Bounds { get; } Gets the image bounds.
BufferSizeHint { get; set; } Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
Container { get; } Gets the Image container.
DataStreamContainer { get; } Gets the object’s data stream.
Disposed { get; } Gets a value indicating whether this instance is disposed.
override FileFormat { get; } Gets a value of file format
virtual HasBackgroundColor { get; set; } Gets or sets a value indicating whether image has background color.
Header { get; set; } Gets or sets the header record
override Height { get; } Gets the image height.
virtual HeightF { get; } Gets the object height, in inches.
InterruptMonitor { get; set; } Gets or sets the interrupt monitor.
override IsCached { get; } Gets a value indicating whether object’s data is cached currently and no data reading is required.
Palette { get; set; } Gets or sets the color palette. The color palette is not used when pixels are represented directly.
override Records { get; set; } Gets or sets the records.
Size { get; } Gets the image size.
SizeF { get; } Gets the object size, in inches.
virtual UsePalette { get; } Gets a value indicating whether the image palette is used.
override Width { get; } Gets the image width.
virtual WidthF { get; } Gets the object width, in inches.

Methods

Name Description
override CacheData() Caches the data and ensures no additional data loading will be performed from the underlying DataStreamContainer.
CanSave(ImageOptionsBase) Determines whether image can be saved to the specified file format represented by the passed save options.
override Crop(Rectangle) Crops the specified rectangle.
virtual Crop(int, int, int, int) Crop image with shifts.
Dispose() Disposes the current instance.
override GetDefaultOptions(object[]) Gets the default options.
virtual GetEmbeddedImages() Gets the embedded images.
GetMissedFonts() Returns the list of fonts which used inside metafile but not found.
virtual GetOriginalOptions() 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 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 method as the second parameter.
override GetUsedFonts() Returns the list of font which used inside metafile.
Resize(int, int) Resizes the image. The default NearestNeighbourResample is used.
override Resize(int, int, ImageResizeSettings) Resizes the image.
override Resize(int, int, ResizeType) Resizes the image.
override ResizeCanvas(Rectangle) Resizes the canvas.
ResizeHeightProportionally(int) Resizes the height proportionally. The default NearestNeighbourResample is used.
virtual ResizeHeightProportionally(int, ImageResizeSettings) Resizes the height proportionally.
virtual ResizeHeightProportionally(int, ResizeType) Resizes the height proportionally.
ResizeWidthProportionally(int) Resizes the width proportionally. The default NearestNeighbourResample is used.
virtual ResizeWidthProportionally(int, ImageResizeSettings) Resizes the width proportionally.
virtual ResizeWidthProportionally(int, ResizeType) Resizes the width proportionally.
override RotateFlip(RotateFlipType) Rotates, flips, or rotates and flips the image.
Save() Saves the image data to the underlying stream.
Save(Stream) Saves the object’s data to the specified stream.
override Save(string) Saves the image to the specified file location.
Save(Stream, ImageOptionsBase) Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, bool) Saves the object’s data to the specified file location.
virtual Save(string, ImageOptionsBase) Saves the object’s data to the specified file location in the specified file format according to save options.
virtual Save(Stream, ImageOptionsBase, Rectangle) Saves the image’s data to the specified stream in the specified file format according to save options.
virtual Save(string, ImageOptionsBase, Rectangle) Saves the object’s data to the specified file location in the specified file format according to save options.
override SetPalette(IColorPalette, bool) Sets the image palette.

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});
}

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});
}

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});
    }
}

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