Skip to main content



      Home
Home » Eclipse Projects » GEF » Can i capture the snapshot of the editor in a JPEG file?
Can i capture the snapshot of the editor in a JPEG file? [message #168723] Thu, 17 February 2005 21:16 Go to next message
Eclipse UserFriend
Hi,

Is there a way to capture the contents of the GEF canvas in a JPEG file ?

thanks,
-Ravi
Re: Can i capture the snapshot of the editor in a JPEG file? [message #168731 is a reply to message #168723] Fri, 18 February 2005 02:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wjancz.\/\/asko.pl(change \/\/ with w)

> Hi,
>
> Is there a way to capture the contents of the GEF canvas in a JPEG file ?
>
> thanks,
> -Ravi
>


Hi!
I am doing it like this (I dont know if there is other solution - if is,
please show me):

used variables:
editor - my editor
number - number used to generate name of file
xCoord - x coordinates of my diagram (where xCoord.x is minimum x coord of
my diagram and xCoord.y is maximum x coord)
yCoord - y coordinates of my diagram (where yCoord.x is minimum y coord of
my diagram and yCoord.y is maximum y coord)


private Image createScreenshot(ComparatorEditor editor, int number, Point
xCoord, Point yCoord) {
Image im = null;
ScalableFreeformRootEditPart editPart = (ScalableFreeformRootEditPart)
editor.getGraphicalViewer().getContents().getRoot();
// getting zoom value - for scaling translations
double zoom = editPart.getZoomManager().getZoom();
// viewport which displays my diagram
Viewport viewer = (Viewport)editPart.getFigure();
// margin
int MARGIN = 10;
// my diagram width - using for image width
int imageWidth = xCoord.y - xCoord.x;
// my diagram height - using for image height
int imageHeight = yCoord.y - yCoord.x;
// scaling image - using diagram width and height multiplied by zoom
value and adding margins
int imageWidthScaled = (int) (imageWidth*zoom) + 2 * (int)(MARGIN *
zoom);
int imageHeightScaled = (int) (imageHeight*zoom) + 2 * (int)(MARGIN
* zoom);

// calculating translations to locate diagram to (0,0) point and
adding margins
int xTranslation = (int) (-xCoord.x * zoom) + (int)(MARGIN * zoom);
int yTranslation = (int) (-yCoord.x * zoom) + (int)(MARGIN * zoom);
// translating viewer
viewer.translate(xTranslation, yTranslation);

// creating new Image
im = new Image(Display.getDefault(), imageWidthScaled,
imageHeightScaled);
GC gc = new GC(im);
SWTGraphics g = new SWTGraphics(gc);
// paint contents on my Image
viewer.paint(g);
// we do not need g and gc anymore
g.dispose();
gc.dispose();

// saving an image to the disk
try {
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[1];
loader.data[0] = im.getImageData();
loader.save("C:\\test"+number+".jpg", SWT.IMAGE_JPEG);
} catch (Exception e) {
e.printStackTrace();
}
return im;
}

...::WojT::..
Re: Can i capture the snapshot of the editor in a JPEG file? [message #169239 is a reply to message #168731] Mon, 21 February 2005 21:42 Go to previous message
Eclipse UserFriend
Hi, this looks like a nice solution. Thanks!! In Swing, we can use the Batik
Plugin to generate the JPEG.. I wonder if we can do the same in SWT too..


"WojT" <wjancz@\/\/asko.pl(change \/\/ with w)> wrote in message
news:cv454j$18v$1@www.eclipse.org...
>> Hi,
>>
>> Is there a way to capture the contents of the GEF canvas in a JPEG file ?
>>
>> thanks,
>> -Ravi
>>
>
>
> Hi!
> I am doing it like this (I dont know if there is other solution - if is,
> please show me):
>
> used variables:
> editor - my editor
> number - number used to generate name of file
> xCoord - x coordinates of my diagram (where xCoord.x is minimum x coord of
> my diagram and xCoord.y is maximum x coord)
> yCoord - y coordinates of my diagram (where yCoord.x is minimum y coord of
> my diagram and yCoord.y is maximum y coord)
>
>
> private Image createScreenshot(ComparatorEditor editor, int number, Point
> xCoord, Point yCoord) {
> Image im = null;
> ScalableFreeformRootEditPart editPart = (ScalableFreeformRootEditPart)
> editor.getGraphicalViewer().getContents().getRoot();
> // getting zoom value - for scaling translations
> double zoom = editPart.getZoomManager().getZoom();
> // viewport which displays my diagram
> Viewport viewer = (Viewport)editPart.getFigure();
> // margin
> int MARGIN = 10;
> // my diagram width - using for image width
> int imageWidth = xCoord.y - xCoord.x;
> // my diagram height - using for image height
> int imageHeight = yCoord.y - yCoord.x;
> // scaling image - using diagram width and height multiplied by
> zoom
> value and adding margins
> int imageWidthScaled = (int) (imageWidth*zoom) + 2 * (int)(MARGIN *
> zoom);
> int imageHeightScaled = (int) (imageHeight*zoom) + 2 * (int)(MARGIN
> * zoom);
>
> // calculating translations to locate diagram to (0,0) point and
> adding margins
> int xTranslation = (int) (-xCoord.x * zoom) + (int)(MARGIN * zoom);
> int yTranslation = (int) (-yCoord.x * zoom) + (int)(MARGIN * zoom);
> // translating viewer
> viewer.translate(xTranslation, yTranslation);
>
> // creating new Image
> im = new Image(Display.getDefault(), imageWidthScaled,
> imageHeightScaled);
> GC gc = new GC(im);
> SWTGraphics g = new SWTGraphics(gc);
> // paint contents on my Image
> viewer.paint(g);
> // we do not need g and gc anymore
> g.dispose();
> gc.dispose();
>
> // saving an image to the disk
> try {
> ImageLoader loader = new ImageLoader();
> loader.data = new ImageData[1];
> loader.data[0] = im.getImageData();
> loader.save("C:\\test"+number+".jpg", SWT.IMAGE_JPEG);
> } catch (Exception e) {
> e.printStackTrace();
> }
> return im;
> }
>
> ..::WojT::..
>
>
>
Previous Topic:SetPropertyValueCommnad used by the UndoablePropertySheetEntry
Next Topic:How to FIT_ALL for newly opened file?
Goto Forum:
  


Current Time: Wed Jun 18 05:58:13 EDT 2025

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

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

Back to the top