Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Export to Image - negative coordinates problem(Problems when exporting GEF to JPG or BMP)
Export to Image - negative coordinates problem [message #897985] Wed, 25 July 2012 14:48 Go to next message
Alexandre Torres is currently offline Alexandre TorresFriend
Messages: 139
Registered: July 2009
Senior Member
Hi, I want to export the entire diagram to JPG or BMP formats. I followed the tips on http://blog.eclipse-tips.com/2008/03/exporting-gef-figure-to-image.html

The first problem I faced was the clipping. This export method applied to my GraphicalEditorWithFlyoutPalette only exports the visible part of my diagram.

I find out an workaround, by setting the bounds of the graphical Viewer figure to the bounds of the PRINTABLE_LAYERS figure before exporting.
It works fine to what is beyond the printing window. But if I have any figure on negative x or y, it will not be exported.
So, what I can't figure out is how to translate the exporting window so that the entire printable area will be printed. I tried to translate the Printable layer (rootFigure variable) but with no success.
I noticied that if I scroll the figure, by hand, to (0,0) before exporting, it works fine BUT it exports the scroll bars...


ScrollingGraphicalViewer graphicalViewer= ...
String saveLocation= ...
		
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) graphicalViewer.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer( LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = graphicalViewer.getControl();
// ENLARGE figureCanvas
org.eclipse.swt.graphics.Rectangle scBounds = figureCanvas.getBounds(); // store original
org.eclipse.swt.graphics.Rectangle swRect = new org.eclipse.swt.graphics.Rectangle(rootFigureBounds.x,rootFigureBounds.y,rootFigureBounds.width,rootFigureBounds.height);
figureCanvas.setBounds(swRect); // I guess that negative x,y will not work for SWT control
// Back to the original code		
Image img = new Image(Display.getDefault(), rootFigureBounds.width, rootFigureBounds.height);  // tried to enlarge this with no success		
//Image img = new Image(Display.getDefault(), swRect); //this won't work either
GC imageGC = new GC(img);
figureCanvas.print(imageGC); 
ImageLoader imgLoader = new ImageLoader();
imgLoader.save(f.getAbsolutePath(), SWT.IMAGE_BMP);
// restore the bounds
figureCanvas.setBounds(scBounds);
// dispose
imageGC.dispose();
img.dispose();	


I think I'm really close... anyone knows what is missing?
Thanks
Re: Export to Image - negative coordinates problem [message #898018 is a reply to message #897985] Wed, 25 July 2012 15:43 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Alexandre,

try this:
final ScrollingGraphicalViewer viewer = ...
final String location = ...

final LayerManager layerManager = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
final IFigure printableLayer = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
final Rectangle printableLayerBounds = printableLayer.getBounds();

final Image img = new Image(Display.getDefault(), printableLayerBounds.width, printableLayerBounds.height);

final GC imageGC = new GC(img);
final SWTGraphics swtGraphics = new SWTGraphics(imageGC);
swtGraphics.translate(printableLayerBounds.getLocation().negate());

printableLayer.paint(swtGraphics);
imageGC.dispose();

final ImageLoader imgLoader = new ImageLoader();
imgLoader.data = new ImageData[] { img.getImageData() };
imgLoader.save(location, SWT.IMAGE_BMP);

img.dispose();
Re: Export to Image - negative coordinates problem [message #898033 is a reply to message #898018] Wed, 25 July 2012 16:17 Go to previous messageGo to next message
Alexandre Torres is currently offline Alexandre TorresFriend
Messages: 139
Registered: July 2009
Senior Member
Great Jan! It works! Smile

Thank you very much!
Re: Export to Image - negative coordinates problem [message #898046 is a reply to message #898033] Wed, 25 July 2012 16:43 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
You're welcome. Don't forget to dispose the SWTGraphics too. I see it's missing there.
Re: Export to Image - negative coordinates problem [message #1738060 is a reply to message #898018] Fri, 15 July 2016 13:24 Go to previous message
Arpit Bhargava is currently offline Arpit BhargavaFriend
Messages: 2
Registered: April 2016
Junior Member
Hi,

Thanks for the input. But this code doesn't work for images created from polygon. Only working for standard shapes. Can you please give some input.

Thanks in advanced.
Previous Topic:Feature Request Draw2d (ToolTip)
Next Topic:GEF4 Zest in Eclipse 4 RCP
Goto Forum:
  


Current Time: Sat Apr 20 01:30:16 GMT 2024

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

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

Back to the top