Zest:将图形输出到图像/ pdf

问题描述:

我已经使用zest框架创建了一个网络视图,这使用SWT显示/ shell来显示UI。我想将UI导出为图像/ pdf。
怎么办?任何想法?

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?

您可以使用SWT GC.copyArea()方法将控件的内容复制到图像,然后将图像保存到文件。例如,如果您有Zest GraphViewer,查看器,以下代码将其内容复制到名为 out.png 的PNG文件。

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();
}