Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problems saving Figure to PNG
Problems saving Figure to PNG [message #1589102] Wed, 28 January 2015 08:35 Go to next message
Stefan Stiebeiner is currently offline Stefan StiebeinerFriend
Messages: 1
Registered: January 2015
Junior Member
Hi,
i have a RCP Application with two Views. (View 1 contains a TreeViewer and View 2 contains a Graph depends on the Selection within the TreeViewer). If you click to one Item within the Treeviewer everything works fine. The Graph is displayed within the second view.
My Problem is the save Procedure of the generated Graphs. Here my Code for saving the Figure to PNG:

    if (view != null) {
	        viewer = ((SchemeList) view).getViewer();
	        for (Object item : ((ITreeContentProvider) viewer.getContentProvider()).getElements(viewer.getInput())) {
	            Object[] contents = ((ITreeContentProvider) viewer.getContentProvider()).getChildren(item);
	            for (Object content : contents) {
	                viewer.expandToLevel(content, AbstractTreeViewer.ALL_LEVELS);
	                //fileName = ((OutputDrawingNode) content).getOutputName() + "-";
	                Object[] results =((ITreeContentProvider) viewer.getContentProvider()).getChildren(content);
	                for (Object result : results) {
	                    
	                    viewer.getControl().setFocus();
                        viewer.setSelection(new StructuredSelection(result), true);
                        IFigure root = ((Drawing) result).getRoot();
                        fileName = fileName + ((Drawing) result).getResultDrawingName() + ".png";
                        org.eclipse.swt.graphics.Rectangle boundingBox = iFigureCanvas.getBounds();
                        Image diagramImage = new Image(iFigureCanvas.getDisplay(), boundingBox.width,
                              boundingBox.height); 
                        GC gc = new GC(diagramImage);
                        SWTGraphics swtGraphics = new SWTGraphics(gc);
                        //    place the painter to the boundingBox's (0,0)
                        swtGraphics.translate(-boundingBox.x, -boundingBox.y); 
                        //paintChildren(swtGraphics, root);
                        paintChildren(swtGraphics, root);
                        ImageLoader imgLoader = new ImageLoader();
                        imgLoader.data = new ImageData[] { diagramImage.getImageData() };
                        imgLoader.save(path + "\\" + fileName, SWT.IMAGE_PNG);
                        swtGraphics.dispose();
                        gc.dispose();
                        diagramImage.dispose();
                        //setFocus();
                        fileName="";
	                    }
	            }
	        }
	    }


Save the Content to PNG create a wrong Picture (See Attachemen wrong-Picture)


If i click to a Item within the Tree and trigger the second View to display the Graph shows the correct Picture: (Attachement goog-picture)

The root Object contains 9 Gradient Rectangle Figures. My Question: have anyone a Idea, why the Rectangles not drawing in the First Process by saving the Picture to PNG.

Thanks a lot

Stefan
Re: Problems saving Figure to PNG [message #1723679 is a reply to message #1589102] Wed, 17 February 2016 08:37 Go to previous message
Vikhyat Prabhu is currently offline Vikhyat PrabhuFriend
Messages: 6
Registered: September 2015
Junior Member
I have a similar problem. But the only difference is my export to SVG or PNG works perfectly when a graphical viewer is open on the UI. But when I try to export it by creating a graphical viewer offscreen referring from the OffScreenEditPartfactory of GMF, I get a output where only the connections of my tree are exported and not the nodes. Exactly similar to the outputs shown in the above post. It would be great if somebody could point to me what could be the problem?
Previous Topic:DirectedGraph: nodes out of order
Next Topic:Javadoc failure when Running a headless build locally
Goto Forum:
  


Current Time: Fri Apr 19 20:36:04 GMT 2024

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

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

Back to the top