Problems saving Figure to PNG [message #1589102] |
Wed, 28 January 2015 08:35 |
Stefan Stiebeiner 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04473 seconds