public class WmfImage extends MetaImage
The Wmf Image
The following example shows how to convert a compressed images (*.emz,*.wmz, *.svgz) to raster format
String[] files = new String[]{ "example.emz", "example.wmz", "example.svgz" };
String baseFolder = "D:\\Compressed\\";
for(String file : files)
{
String inputFile = (baseFolder + file);
String outFile = inputFile + ".png";
try (com.aspose.imaging.Image image = com.aspose.imaging.Image.load(inputFile))
{
final com.aspose.imaging.imageoptions.VectorRasterizationOptions vectorRasterizationOptions =
(com.aspose.imaging.imageoptions.VectorRasterizationOptions) image.getDefaultOptions(new Object[]{Color.getWhite(), image.getWidth(), image.getHeight()});
image.save(outFile, new com.aspose.imaging.imageoptions.PngOptions()
{{
setVectorRasterizationOptions(vectorRasterizationOptions);
}});
}
}
| Constructor and Description |
|---|
WmfImage()
Initializes a new instance of the
WmfImage class. |
WmfImage(int width,
int height)
Initializes a new instance of the
WmfImage class. |
| Modifier and Type | Method and Description |
|---|---|
int |
addRecord(WmfObject record)
Adds the record.
|
void |
cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying
DataStreamSupporter.DataStreamContainer. |
void |
crop(Rectangle rectangle)
Crops the specified rectangle.
|
int |
getBitsPerPixel()
Gets the image bits per pixel count.
|
ImageOptionsBase |
getDefaultOptions(Object[] args)
Gets the default options.
|
long |
getFileFormat()
Gets a value of file format
|
Rectangle |
getFrameBounds()
Gets the frame bounds.
|
int |
getHeight()
Gets the image height.
|
int |
getInch()
Gets or sets the inch.
|
String |
getPostScript()
Gets the post script.
|
String[] |
getUsedFonts()
Returns the list of font which used inside metafile.
|
int |
getWidth()
Gets the image width.
|
boolean |
isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
|
void |
resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Resizes the image.
|
void |
resize(int newWidth,
int newHeight,
int resizeType)
Resizes the image.
|
void |
resizeCanvas(Rectangle newRectangle)
Resizes the canvas.
|
void |
rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
|
void |
setInch(int value)
Gets or sets the inch.
|
void |
setPalette(IColorPalette palette,
boolean updateColors)
Sets the image palette.
|
crop, getMissedFonts, getRecords, setRecordsgetEmbeddedImages, getHeightF, getSizeF, getWidthFcanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, hasBackgroundColor, isAutoAdjustPalette, isUsePalette, load, load, load, load, load, load, 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 WmfImage()
Initializes a new instance of the WmfImage class.
public WmfImage(int width,
int height)
Initializes a new instance of the WmfImage class.
width - The width.height - The height.public boolean isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
isCached in class DataStreamSupportercom.aspose.ms.System.NotImplementedException - Value:
true if object's data is cached; otherwise, false.public int getBitsPerPixel()
Gets the image bits per pixel count.
getBitsPerPixel in class Imagecom.aspose.ms.System.NotImplementedException - Value:
The image bits per pixel count.public int getWidth()
Gets the image width.
getWidth in interface IObjectWithBoundsgetWidth in class VectorImagecom.aspose.ms.System.NotImplementedException - Value:
The image width.public int getHeight()
Gets the image height.
getHeight in interface IObjectWithBoundsgetHeight in class VectorImagecom.aspose.ms.System.NotImplementedException - Value:
The image height.public int getInch()
Gets or sets the inch.
Value: The inch.public void setInch(int value)
Gets or sets the inch.
Value: The inch.public long getFileFormat()
Gets a value of file format
getFileFormat in class ImageFileFormatpublic final Rectangle getFrameBounds()
Gets the frame bounds.
Value: The frame bounds.public void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying
DataStreamSupporter.DataStreamContainer.
cacheData in class DataStreamSupportercom.aspose.ms.System.NotImplementedException - this feature is not implementedThis 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 resize(int newWidth,
int newHeight,
int resizeType)
Resizes the image.
resize in class ImagenewWidth - The new width.newHeight - The new height.resizeType - The resize type.com.aspose.ms.System.NotImplementedException - this feature is not implementedThis example loads a WMF image and resizes it using various resizing methods.
String dir = "c:\\temp\\";
com.aspose.imaging.fileformats.wmf.WmfImage image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
try {
// Scale up by 2 times using Nearest Neighbour resampling.
image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
try {
// Scale down by 2 times using Nearest Neighbour resampling.
image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.NearestNeighbourResample);
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
try {
// Scale up by 2 times using Bilinear resampling.
image.resize(image.getWidth() * 2, image.getHeight() * 2, com.aspose.imaging.ResizeType.BilinearResample);
} finally {
image.dispose();
}
image = (com.aspose.imaging.fileformats.wmf.WmfImage) com.aspose.imaging.Image.load(dir + "sample.wmf");
try {
// Scale down by 2 times using Bilinear resampling.
image.resize(image.getWidth() / 2, image.getHeight() / 2, com.aspose.imaging.ResizeType.BilinearResample);
} finally {
image.dispose();
}
public void resize(int newWidth,
int newHeight,
ImageResizeSettings settings)
Resizes the image.
public void rotateFlip(int rotateFlipType)
Rotates, flips, or rotates and flips the image.
rotateFlip in class ImagerotateFlipType - Type of the rotation and flipping.com.aspose.ms.System.NotImplementedException - this feature is not implementedpublic 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 - this feature is not implementedpublic String[] getUsedFonts()
Returns the list of font which used inside metafile.
getUsedFonts in class MetaImagepublic ImageOptionsBase getDefaultOptions(Object[] args)
Gets the default options.
getDefaultOptions in class Imageargs - The arguments.public void crop(Rectangle rectangle)
Crops the specified rectangle.
public void resizeCanvas(Rectangle newRectangle)
Resizes the canvas.
resizeCanvas in class MetaImagenewRectangle - The new rectangle.public int addRecord(WmfObject record)
Adds the record.
record - The record.public final String getPostScript()
Gets the post script.
Copyright (c) 2008-2022 Aspose Pty Ltd. All Rights Reserved.