|
Re: How to draw IFigure into Image [message #686604 is a reply to message #684898] |
Wed, 22 June 2011 15:25 |
h1055071 Messages: 335 Registered: July 2009 |
Senior Member |
|
|
How about this:
public Image createScaledImage(GraphicalViewer graphicalViewer, double scale) {
IFigure figure = ((FreeformGraphicalRootEditPart)graphicalViewer.getRootEditPart()).getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle extents = figure.getBounds().getCopy();
Image image = new Image(Display.getDefault(), (int)(extents.width * scale), (int)(extents.height * scale) );
GC gc = new GC(image);
SWTGraphics swtGraphics = new SWTGraphics(gc);
Graphics graphics = swtGraphics;
// If scaled, then scale now
if(scale != 1) {
graphics = new ScaledGraphics(swtGraphics);
graphics.scale(scale);
}
// Compensate for negative co-ordinates
graphics.translate(extents.x * -1, extents.y * -1);
// Paint onto graphics
figure.paint(graphics);
// Dispose
gc.dispose();
graphics.dispose();
if(swtGraphics != graphics) {
swtGraphics.dispose();
}
return image;
}
[Updated on: Wed, 22 June 2011 15:26] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03950 seconds