问题
I have created a network view diagram using zest framework, this uses SWT display/shell to display the UI. I want to export the UI to an image/pdf. How to do it? Any ideas?
回答1:
You can use the SWT GC.copyArea() method to copy the contents of a Control to an Image, then save the Image to file. For example, if you have a Zest GraphViewer, viewer, the following code will copy its contents to a PNG file named out.png.
GC gc = new GC(viewer.getControl());
Rectangle bounds = viewer.getControl().getBounds();
Image image = new Image(viewer.getControl().getDisplay(), bounds);
try {
gc.copyArea(image, 0, 0);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save("c:\\out.png", SWT.IMAGE_PNG);
} finally {
image.dispose();
gc.dispose();
}
来源:https://stackoverflow.com/questions/9718446/zest-export-diagram-to-an-image-pdf