将GEF模型显示保存为图片

本文介绍了一种将GEF模型在编辑器中的显示保存为图片的方法,以便于预览或文档使用。通过SWTGraphics实现GEF图像的保存,并详细解释了获取背景层和打印层的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目需求,要把GEF模型在editor中的显示保存为一张图片,便于预览或在文档中使用。研究了GMF的代码,它使用AWT来进行图片的输出,所以在中间作了一个SWT和AWT的转换Adapter. 是一个叫做AWTGraphics的类.其实使用SWT本身就可以进行。
使用draw2D提供的SWTGraphics可以进行GEG图像的保存。本程序假定读者对GEF有一定了解。

privatevoidsaveOutlinePicture(ScrollingGraphicalViewerviewer)...{
LayerManagerlayerManager
=(LayerManager)viewer.getEditPartRegistry().get(LayerManager.ID);
//saveimageusingswt
//getrootfigure
// 获取显示在editor中的背景层和打印层
IFigurebackgroundLayer=layerManager.getLayer(LayerConstants.GRID_LAYER);

IFigurecontentLayer
=layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);

//createimagefromrootfigure
Imageimg=newImage(null,contentLayer.getSize().width,contentLayer.getSize().height);
GCgc
=newGC(img);
Graphicsgraphics
=newSWTGraphics(gc);
graphics.translate(contentLayer.getBounds().getLocation());
// 传送显示图层
backgroundLayer.paint(graphics);
contentLayer.paint(graphics);
graphics.dispose();
gc.dispose();

//saveimagetofile
ImageLoaderil=newImageLoader();
il.data
=newImageData[]...{img.getImageData()};

//保存地址和保存图片的类型

il.save(“c:/test.jpg",SWT.IMAGE_JPEG);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值