[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.gef] Re: Export to png or jpeg
|
- From: Remko Popma <remko.popma@xxxxxxxxxx>
- Date: Sat, 24 Jan 2004 23:10:09 +0900
- Newsgroups: eclipse.tools.gef
- Organization: EclipseCorner
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
Antonio,
Here is some code for exporting a GEF figure to an image.
Regards,
Remko Popma
/**
* Returns the bytes of an encoded image for the specified
* IFigure in the specified format.
*
* @param figure the Figure to create an image for.
* @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF
* SWT.IMAGE_ICO, SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
* @return the bytes of an encoded image for the specified Figure
*/
private byte[] createImage(IFigure figure, int format) {
Device device = getEditPartViewer().getControl().getDisplay();
Rectangle r = figure.getBounds();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, r.width, r.height);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(r.x * -1, r.y * -1);
figure.paint(g);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] {image.getImageData()};
imageLoader.save(result, format);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Antonio Muñoz wrote:
Does anybody know how to export a gef diagram / image to a png image (or
jpeg) ?
I tryed to export it to svg directly to, afterwards, transform it to a
jpeg image. But I didn't found a way to do it.
Thanx