How to save a Figure in a Jpg [message #116763] |
Tue, 10 February 2004 09:51 |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: jgonzalo99.hotmail.com
Hi all.
How can I save a JPG file of a flow diagram?
I'm using the following code, but the image generated in the file put all
the figures of the graph in the upper left side.
Maybe I've got to layout the rootEditPart before printing it or I've got
to use LayerConstants.PRINTABLE_LAYERS in some way.
Thanks in advance.
// I get the rootEditPart for printing it
Figure figure =
((AbstractGraphicalEditPart)getGraphicalViewer().getRootEdit Part()).getFigure();
externalize(figure);
private void externalize(IFigure figure)
{
Rectangle r = figure.getClientArea();
Image image = new Image(Display.getCurrent(), r.width, r.height);
GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
figure.paint(graphics);
try
{
File file = new File("d:/temp/figure.jpg");
if (!file.exists())
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save(fos, SWT.IMAGE_JPEG);
}
catch (Exception e)
{
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02869 seconds