public class WmfRectangle extends WmfObject
The META_RECTANGLE record paints a rectangle. The rectangle is outlined by using the pen and filled by using the brush that are defined in the playback device context.
Constructor and Description |
---|
WmfRectangle() |
Modifier and Type | Method and Description |
---|---|
Rectangle |
getRectangle()
Gets or sets the rectangle.
|
void |
setRectangle(Rectangle value)
Gets or sets the rectangle.
|
public WmfRectangle()
The following example shows how set the background color for WMF. Actually it draws a rectangle of the background color before drawing all other objects.
String baseFolder = "c:\\temp\\"; // This is a helper class which does all real work. class Util { public void addBackgroundRectangleWmf(com.aspose.imaging.fileformats.wmf.WmfImage image, com.aspose.imaging.Color color) { image.cacheData(); com.aspose.imaging.fileformats.emf.MetaObjectList records = image.getRecords(); if (records.size() < 1) { return; } //Set Rectangle com.aspose.imaging.fileformats.wmf.objects.WmfRectangle rectangle = new com.aspose.imaging.fileformats.wmf.objects.WmfRectangle(); rectangle.setRectangle(image.getFrameBounds()); //Set Brush com.aspose.imaging.fileformats.wmf.objects.WmfCreateBrushInDirect brush = new com.aspose.imaging.fileformats.wmf.objects.WmfCreateBrushInDirect(); brush.setLogBrush(new com.aspose.imaging.fileformats.emf.emf.objects.EmfLogBrushEx()); brush.getLogBrush().setArgb32ColorRef(color.toArgb()); //Select brush com.aspose.imaging.fileformats.wmf.objects.WmfSelectObject selectObject = new com.aspose.imaging.fileformats.wmf.objects.WmfSelectObject(brush); //Remove brush com.aspose.imaging.fileformats.wmf.objects.WmfDeleteObject deleteObject = new com.aspose.imaging.fileformats.wmf.objects.WmfDeleteObject(brush); //Add records records.insertItem(0, brush); records.insertItem(1, selectObject); records.insertItem(2, rectangle); records.insertItem(3, deleteObject); } } String[] files = new String[]{"image1.emf", "image2.wmf"}; for (String fileName : files) { String inputFile = baseFolder + fileName; String outputFile = baseFolder + "Background_" + fileName; com.aspose.imaging.fileformats.emf.MetaImage image = (com.aspose.imaging.fileformats.emf.MetaImage) com.aspose.imaging.Image.load(inputFile); try { new Util().addBackgroundRectangleWmf((com.aspose.imaging.fileformats.wmf.WmfImage) image, com.aspose.imaging.Color.getBlue()); image.save(outputFile); } finally { image.close(); } }