Zest: export diagram to an image/pdf

时光总嘲笑我的痴心妄想 提交于 2019-12-12 21:58:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!