save an IFigure to a gif [message #326610] |
Wed, 26 March 2008 13:30 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Hi,
I already posted a similar message in gef and swt newsgroup but didn't
get any response so I'm trying there.
I want to generate a number of gif of a particular figure and it's
children selected from the rootfigure of a diagram.
I want to do this without opening an editor. So I developped the
following method to generate an image from a particular figure
private byte[] createImage(IFigure figure, int format) {
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new
Image(null,figure.getBounds().width,figure.getBounds().heigh t);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(figure.getBounds().x * -1, figure.getBounds().y * -1);
figure.paint(g);
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[1];
ImageData imageData = image.getImageData();
/* If the image depth is 8 bits or less, then we can use the
existing image data. */
if (imageData.depth <= 8) {
loader.data[0] = imageData;
}else {
/* get an 8 bit imageData for the image */
ImageData newImageData =
CreateImageAction.get8BitPaletteImageData(imageData);
loader.data[0] = newImageData;
}
loader.save(result, format);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
I've two problems with this method, the first is my figure and it's
children doesn't have the bounds set.
The second problem is when generating the images my figure and it's
children are not paint
What can be the cause ?
Thanks for your help
Alexandre
|
|
|
Re: save an IFigure to a gif [message #326617 is a reply to message #326610] |
Wed, 26 March 2008 14:42 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Sorry in fact it's work if the selected figure have been setted as
visible in the model
But if I try to force the property visible to paint it's content the
result is a blank image
condition.setVisible(true);
condition.paint(g);
any idea ?
Thanks
|
|
|
Powered by
FUDForum. Page generated in 0.04177 seconds