[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.gef] Re: Export to png or jpeg
|
Actually it frequently can not save.
For example, in PNGFileFormat:
void unloadIntoByteStream(ImageData p1) {
SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
}
So snippet do not solve problem with PNG yet.
"Randy Hudson" <none@xxxxxxxxxx> wrote in message
news:bv3bnt$5gc$1@xxxxxxxxxxxxxx
> Thanks for the code snippet! We'll add this to a snippets page.
>
> Am I the only one who thinks it's funny that "ImageLoader" save files??
>
> "Remko Popma" <remko.popma@xxxxxxxxxx> wrote in message
> news:butu88$jnn$1@xxxxxxxxxxxxxx
> > 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
> > >
> >
>
>