[ZEST] png export [message #1077152] |
Thu, 01 August 2013 09:58 |
Low Coupling Messages: 30 Registered: June 2013 |
Member |
|
|
I'd like to programmatically create a zest diagram and export it as a png.
I have managed to create the diagram by means of a GraphViewer instance having as composite parent a shell instaniated this way:
Shell shell = new Shell(Display.getDefault());
Note that the graph is not shown.
I can't see now how to export the graph in a png file. Is there any way to do that?
[Updated on: Thu, 01 August 2013 09:59] Report message to a moderator
|
|
|
Re: [ZEST] png export [message #1077268 is a reply to message #1077152] |
Thu, 01 August 2013 13:08 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
Senior Member |
|
|
Hi,
yes, it is possible to export the contents of the graph as a png. See the following snippet (we have used this in the VIATRA2 project in http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.viatra2/trunk/plugins/org.eclipse.viatra2.visualisation/src/org/eclipse/viatra2/visualisation/ViatraGraphViewer.java); it does not need to be defined inside a GraphViewer, it only needs a reference to the Graph widget.
Graph g = (Graph) getControl();
Rectangle bounds = g.getContents().getBounds();
Point size = new Point(g.getContents().getSize().width, g.getContents()
.getSize().height);
org.eclipse.draw2d.geometry.Point viewLocation = g.getViewport()
.getViewLocation();
final Image image = new Image(null, size.x, size.y);
GC gc = new GC(image);
SWTGraphics swtGraphics = new SWTGraphics(gc);
swtGraphics.translate(-1 * bounds.x + viewLocation.x, -1 * bounds.y
+ viewLocation.y);
g.getViewport().paint(swtGraphics);
gc.copyArea(image, 0, 0);
gc.dispose();
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save(filename, format);
Hope this helps. Cheers,
Zoltán
|
|
|
Powered by
FUDForum. Page generated in 0.02628 seconds