Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to save a Figure in a Jpg
How to save a Figure in a Jpg [message #116763] Tue, 10 February 2004 09:51
Eclipse UserFriend
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)
{
}
}
Previous Topic:Migrating from GEF 2.0,2 to 2.1.1
Next Topic:Changing Z order
Goto Forum:
  


Current Time: Sat Jul 27 13:27:00 GMT 2024

Powered by FUDForum. Page generated in 0.02905 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top