public final class EmfImage extends MetaImage
EMF file format image.
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()
Initializes a new instance of the
EmfImage class. |
Modifier and Type | Method and Description |
---|---|
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 this parameter is not applicable to vector images
|
ImageOptionsBase |
getDefaultOptions(Object[] args)
Gets the default options.
|
long |
getFileFormat()
Gets a value of file format
|
EmfMetafileHeader |
getHeader()
Gets or sets the header record
|
int |
getHeight()
Gets the image height.
|
MetaObjectList |
getRecords()
Gets or sets the records.
|
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 |
setHeader(EmfMetafileHeader value)
Gets or sets the header record
|
void |
setPalette(IColorPalette palette,
boolean updateColors)
Sets the image palette.
|
void |
setRecords(MetaObjectList value)
Gets or sets the records.
|
crop, getMissedFonts
getHeightF, getSizeF, getWidthF
canLoad, canLoad, canLoad, canLoad, canSave, create, getBackgroundColor, getBounds, getBufferSizeHint, getContainer, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getOriginalOptions, getPalette, getProgressEventHandler, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSize, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBackgroundColor, setBufferSizeHint, setInterruptMonitor, setPalette
getDataStreamContainer, save, save, save, save
close, dispose, getDisposed
public EmfMetafileHeader getHeader()
Gets or sets the header record
public void setHeader(EmfMetafileHeader value)
Gets or sets the header record
public boolean isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
Value:true
if object's data is cached; otherwise, false
.isCached
in class DataStreamSupporter
public MetaObjectList getRecords()
Gets or sets the records.
Value: The records.getRecords
in class MetaImage
public void setRecords(MetaObjectList value)
Gets or sets the records.
Value: The records.setRecords
in class MetaImage
value
- The records.public long getFileFormat()
Gets a value of file format
getFileFormat
in class Image
public int getBitsPerPixel()
Gets the image bits per pixel count this parameter is not applicable to vector images
getBitsPerPixel
in class Image
com.aspose.ms.System.NotImplementedException
- Not valid for vector images
Value:
The image bits per pixel count.public int getWidth()
Gets the image width.
Value: The image width.getWidth
in interface IObjectWithBounds
getWidth
in class VectorImage
public int getHeight()
Gets the image height.
Value: The image height.getHeight
in interface IObjectWithBounds
getHeight
in class VectorImage
public void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer
.
cacheData
in class DataStreamSupporter
This 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()
Returns the list of font which used inside metafile.
getUsedFonts
in class MetaImage
public void crop(Rectangle rectangle)
Crops the specified rectangle.
public void resizeCanvas(Rectangle newRectangle)
Resizes the canvas.
resizeCanvas
in class MetaImage
newRectangle
- The new rectangle.public void resize(int newWidth, int newHeight, int resizeType)
Resizes the image.
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 Image
rotateFlipType
- Type of the rotate flip.com.aspose.ms.System.NotImplementedException
- Not implemented.public void setPalette(IColorPalette palette, boolean updateColors)
Sets the image palette.
setPalette
in class Image
palette
- 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 valid for vector imagespublic ImageOptionsBase getDefaultOptions(Object[] args)
Gets the default options.
getDefaultOptions
in class Image
args
- The arguments.