public final class EmfImage extends MetaImage
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.
This example shows how to load a EMF image from a file and convert it to SVG using EmfRasterizationOptions.
String dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including EMF.
com.aspose.imaging.fileformats.emf.EmfImage emfImage = (com.aspose.imaging.fileformats.emf.EmfImage) com.aspose.imaging.Image.load(dir + "test.emf");
try {
com.aspose.imaging.imageoptions.SvgOptions saveOptions = new com.aspose.imaging.imageoptions.SvgOptions();
// Text will be converted to shapes.
saveOptions.setTextAsShapes(true);
com.aspose.imaging.imageoptions.EmfRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.EmfRasterizationOptions();
// The background color of the drawing surface.
rasterizationOptions.setBackgroundColor(com.aspose.imaging.Color.getWhiteSmoke());
// The page size.
rasterizationOptions.setPageSize(new com.aspose.imaging.SizeF(emfImage.getWidth(), emfImage.getHeight()));
// If embedded emf exists, then render emf; otherwise render wmf.
rasterizationOptions.setRenderMode(com.aspose.imaging.fileformats.emf.EmfRenderMode.Auto);
// Set the horizontal margin
rasterizationOptions.setBorderX(50);
// Set the vertical margin
rasterizationOptions.setBorderY(50);
saveOptions.setVectorRasterizationOptions(rasterizationOptions);
emfImage.save(dir + "test.output.svg", saveOptions);
} finally {
emfImage.dispose();
}
| Constructor and Description |
|---|
EmfImage()
Start working with EMF images by initializing a new instance of the
EmfImage class. |
EmfImage(int width,
int height)
Create a new instance of the
EmfImage class by specifying the width
and height parameters. |
| Modifier and Type | Method and Description |
|---|---|
void |
cacheData()
Efficiently cache data and prevent redundant loading from the underlying
DataStreamSupporter.DataStreamContainer(DataStreamSupporter.getDataStreamContainer() with this method. |
int |
getBitsPerPixel()
Retrieve the bit-per-pixel count specific to raster images, as this parameter
doesn't apply to vector images.
|
long |
getFileFormat()
Access the file format value associated with the object.
|
EmfMetafileHeader |
getHeader()
Retrieve the EMF metafile header record with this property.
|
float |
getHeightF()
Retrieve the image's height, facilitating accurate rendering and layout adjustments.
|
ImageOptionsBase |
getOriginalOptions()
Gets the original image options.
|
MetaObjectList |
getRecords()
Retrieve or modify the records associated with the object.
|
String[] |
getUsedFonts()
Retrieve the list of fonts utilized within the metafile with this method.
|
float |
getWidthF()
Access to the width of the image, providing essential information for precise
rendering and processing.
|
boolean |
isCached()
Access a value indicating whether the object's data is currently cached,
eliminating the need for additional data reading.
|
void |
resizeCanvas(Rectangle newRectangle)
Resize the canvas with ease using this function.
|
void |
setHeader(EmfMetafileHeader value)
Modify the EMF metafile header record with this property.
|
void |
setPalette(IColorPalette palette,
boolean updateColors)
Sets the image palette.
|
void |
setRecords(MetaObjectList value)
Modify the records associated with the object.
|
getMissedFontscrop, getDefaultOptions, getEmbeddedImages, getHeight, getSizeF, getWidth, removeBackground, removeBackground, resize, resize, rotate, rotateFlipcanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, crop, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, hasBackgroundColor, isAutoAdjustPalette, isUsePalette, load, load, load, load, load, load, removeMetadata, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalettegetDataStreamContainer, save, save, saveclose, dispose, getDisposedpublic EmfImage()
Start working with EMF images by initializing a new instance of the
EmfImage class. Ideal for quickly incorporating EMF images into
your projects with ease and efficiency.
public EmfImage(int width,
int height)
Create a new instance of the 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.
width - The width.height - The height.public EmfMetafileHeader getHeader()
Retrieve 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 void setHeader(EmfMetafileHeader value)
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 boolean 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.
isCached in class DataStreamSupportertrue if object's data is cached; otherwise, false.public MetaObjectList getRecords()
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.
getRecords in class MetaImagepublic void setRecords(MetaObjectList value)
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.
setRecords in class MetaImagevalue - The records.public long getFileFormat()
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.
getFileFormat in class ImageFileFormatpublic int getBitsPerPixel()
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.
getBitsPerPixel in class Imagecom.aspose.ms.System.NotImplementedException - Invalid for vector images.public float getWidthF()
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.
getWidthF in interface IObjectWithSizeFgetWidthF in class VectorImagepublic float getHeightF()
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.
getHeightF in interface IObjectWithSizeFgetHeightF in class VectorImagepublic void cacheData()
Efficiently cache data and prevent redundant loading from the underlying
DataStreamSupporter.DataStreamContainer(DataStreamSupporter.getDataStreamContainer() with this method. Enhance
performance and streamline data access in your application, optimizing resource
utilization for improved responsiveness.
cacheData in class DataStreamSupporterThis example shows how to load a EMF image from a file and list all of its records.
String dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including WMF.
com.aspose.imaging.fileformats.emf.EmfImage emfImage = (com.aspose.imaging.fileformats.emf.EmfImage) com.aspose.imaging.Image.load(dir + "test.emf");
try {
// Cache data to load all records.
emfImage.cacheData();
System.out.println("The total number of records: " + emfImage.getRecords().size());
// The key is a record type, the value is number of records of that type in the WMF image.
java.util.HashMap<Class, Integer> types =
new java.util.HashMap<>();
// Gather statistics
for (Object obj : emfImage.getRecords()) {
com.aspose.imaging.fileformats.emf.emf.records.EmfRecord record = (com.aspose.imaging.fileformats.emf.emf.records.EmfRecord) obj;
Class objType = record.getClass();
if (!types.containsKey(objType)) {
types.put(objType, 1);
} else {
int n = types.get(objType);
types.put(objType, n + 1);
}
}
// Print statistics
System.out.println("Record Type Count");
System.out.println("----------------------------------------------");
for (java.util.Map.Entry<Class, Integer> entry : types.entrySet()) {
String objectType = entry.getKey().getSimpleName();
int numberOfEntrances = entry.getValue();
// Align output with spaces
int alignmentPos = 40;
char[] chars = new char[alignmentPos - objectType.length()];
java.util.Arrays.fill(chars, ' ');
String gap = new String(chars);
System.out.println(objectType + ":" + gap + numberOfEntrances);
}
} finally {
emfImage.dispose();
}
//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
public String[] 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.
getUsedFonts in class MetaImagepublic void resizeCanvas(Rectangle newRectangle)
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.
resizeCanvas in class MetaImagenewRectangle - The new rectangle.public ImageOptionsBase getOriginalOptions()
Gets the original image options.
getOriginalOptions in class Imagepublic void setPalette(IColorPalette palette, boolean updateColors)
Sets the image palette.
setPalette in class Imagepalette - The palette to set.updateColors - 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.com.aspose.ms.System.NotImplementedException - Not implemented.Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.