public class WmfImage extends MetaImage
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.
This example shows how to load a WMF image from a file and convert it to SVG using WmfRasterizationOptions.
String dir = "c:\\temp\\";
// Using Aspose.Imaging.Image.Load is a unified way to load all types of images including WMF.
try (com.aspose.imaging.fileformats.wmf.WmfImage wmfImage = (com.aspose.imaging.fileformats.wmf.WmfImage)com.aspose.imaging.Image.load(dir + "test.wmf"))
{
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.WmfRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.WmfRasterizationOptions();
// The background color of the drawing surface.
rasterizationOptions.setBackgroundColor(com.aspose.imaging.Color.getWhiteSmoke());
// The page size.
rasterizationOptions.setPageSize(Size.to_SizeF(wmfImage.getSize()));
// If embedded emf exists, then render emf; otherwise render wmf.
rasterizationOptions.setRenderMode(com.aspose.imaging.fileformats.wmf.WmfRenderMode.Auto);
saveOptions.setVectorRasterizationOptions(rasterizationOptions);
wmfImage.save(dir + "test.output.svg", saveOptions);
}
| Constructor and Description |
|---|
WmfImage()
Create a new instance of the
WmfImage class, initializing it for
further manipulation and processing of Windows Metafile (WMF) image data. |
WmfImage(int width,
int height)
Instantiate a new instance of the
WmfImage class with customizable
width and height parameters, facilitating the creation of blank WMF images
tailored to specific dimensions. |
| Modifier and Type | Method and Description |
|---|---|
int |
addRecord(WmfObject record)
Incorporate the specified record object into the image, enriching its content with
additional data or metadata.
|
void |
cacheData()
Efficiently cache the data, eliminating the need for additional loading from the
underlying
DataStreamSupporter.DataStreamContainer(DataStreamSupporter.getDataStreamContainer()). |
int |
getBitsPerPixel()
Retrieve the count of bits per pixel for the image, indicating the level of color
depth or granularity.
|
long |
getFileFormat()
Access the file format value associated with the image, providing information
about the format in which the image is stored.
|
Rectangle |
getFrameBounds()
Access the bounds of the frame, indicating its position and dimensions within the
image.
|
float |
getHeightF()
Access the image's height, representing the number of pixels along its vertical
axis.
|
int |
getInch()
Access or modify the inch property, representing a unit of measurement typically
used for specifying physical dimensions in print or display contexts.
|
ImageOptionsBase |
getOriginalOptions()
Gets the original image options.
|
String |
getPostScript()
Access the PostScript data associated with the image, providing detailed
information about its structure or content.
|
String[] |
getUsedFonts()
Retrieve the list of fonts used within the metafile, providing insight into the
font resources utilized in the image.
|
float |
getWidthF()
Access the width of the image, indicating the number of pixels along its
horizontal axis.
|
boolean |
isCached()
Retrieve a boolean value indicating whether the object's data is currently cached,
eliminating the need for additional data reading operations.
|
void |
resizeCanvas(Rectangle newRectangle)
Resize the canvas of the image, adjusting its dimensions while retaining the image
content.
|
void |
setInch(int value)
Access or modify the inch property, representing a unit of measurement typically
used for specifying physical dimensions in print or display contexts.
|
void |
setPalette(IColorPalette palette,
boolean updateColors)
Apply a specified palette to the image, enabling customization of color
representation.
|
getMissedFonts, getRecords, setRecordscrop, getDefaultOptions, getEmbeddedImages, getHeight, getSizeF, getWidth, removeBackground, removeBackground, resize, resize, rotate, rotateFlipcanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, create, crop, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getExifData, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getMetadata, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, getXmpData, 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, setExifData, setInterruptMonitor, setPalette, setXmpData, trySetMetadatagetDataStreamContainer, save, save, saveclose, dispose, getDisposedpublic WmfImage()
Create a new instance of the 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.
public WmfImage(int width,
int height)
Instantiate a new instance of the 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.
width - The width.height - The height.public boolean 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.
isCached in class DataStreamSupportercom.aspose.ms.System.NotImplementedException - Value:
true if object's data is cached; otherwise, false.public int getBitsPerPixel()
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.
getBitsPerPixel in class Imagecom.aspose.ms.System.NotImplementedException - Value:
The image bits per pixel count.public float getWidthF()
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.
getWidthF in interface IObjectWithSizeFgetWidthF in class VectorImagepublic float getHeightF()
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.
getHeightF in interface IObjectWithSizeFgetHeightF in class VectorImagepublic int getInch()
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 void setInch(int value)
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 long getFileFormat()
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.
getFileFormat in class ImageFileFormatpublic final Rectangle getFrameBounds()
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 void cacheData()
Efficiently cache the data, eliminating the need for additional loading from the
underlying DataStreamSupporter.DataStreamContainer(DataStreamSupporter.getDataStreamContainer()).
Utilize this method to optimize performance and minimize resource usage within your application
by storing and accessing local data cache.
cacheData in class DataStreamSupporterThis example shows how to load a WMF 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.wmf.WmfImage wmfImage = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "test.wmf");
try {
// Cache data to load all records.
wmfImage.cacheData();
System.out.println("The total number of records: " + wmfImage.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 : wmfImage.getRecords()) {
com.aspose.imaging.fileformats.wmf.objects.WmfObject wmfObj = (com.aspose.imaging.fileformats.wmf.objects.WmfObject) obj;
Class objType = wmfObj.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 {
wmfImage.dispose();
}
//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
public void setPalette(IColorPalette palette, boolean updateColors)
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.
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 - this feature is not implementedpublic String[] 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.
getUsedFonts in class MetaImagepublic void resizeCanvas(Rectangle newRectangle)
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.
resizeCanvas in class MetaImagenewRectangle - The new rectangle.public int addRecord(WmfObject record)
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.
record - The record.public final String 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 ImageOptionsBase getOriginalOptions()
Gets the original image options.
getOriginalOptions in class ImageCopyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.