Skip to main content



      Home
Home » Eclipse Projects » GEF » Help: How to export the GEF figure to Diagram graphic?
Help: How to export the GEF figure to Diagram graphic? [message #79900] Sun, 18 May 2003 11:28 Go to next message
Eclipse UserFriend
Originally posted by: yuancong.tsinghua.org.cn

Is there a way to print GEF figure into a gif/jpg/wmf file? Who can give me
an example? Thanks
Re: Help: How to export the GEF figure to Diagram graphic? [message #79958 is a reply to message #79900] Mon, 19 May 2003 00:02 Go to previous message
Eclipse UserFriend
Originally posted by: scheglov_ke.nlmk.ru

YUAN Cong <yuancong@tsinghua.org.cn> wrote:

> Is there a way to print GEF figure into a gif/jpg/wmf file? Who can give me
> an example? Thanks
Here is export support from my profiler plugin.
As you can see, I just create image needed size, then GC for it.
Then I wrap this GC in SWTGraphics and paint figure in it.
Jimi can by found on SUN.
SaveGif uses PJA (use google to find).

For WMF you will need to use native Win32 code to create WMF and receive
HDC for it. Then you can use this HDC for creating GC and then use same way.

protected void export() {
IPreferenceStore preferences = ProfilerPlugin.getDefault().getPreferenceStore();
FileDialog saveDialog = new FileDialog(m_Control.getShell(), SWT.SAVE);
saveDialog.setFilterExtensions(new String[] { "*.png", "*.gif", "*.jpg" });
saveDialog.setFilterNames(new String[] { "PNG files (*.png)", "GIF files (*.gif)", "JPG files (*.jpg)" });
saveDialog.setFileName(StringUtils.chomp(preferences.getStri ng(IProfilerUIConstants.EXPORT_GIF_PATH), "."));
String path = saveDialog.open();
if (path == null)
return;
preferences.putValue(IProfilerUIConstants.EXPORT_GIF_PATH, path);
//
int w = m_Root.getSize().width;
int h = m_Root.getSize().height;
Image image = new Image(m_Control.getDisplay(), w, h);
GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
m_Root.paint(graphics);
graphics.dispose();
gc.dispose();
//
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData()};
final String tmpPath = path + "__tmp.bmp";
imageLoader.save(tmpPath, SWT.IMAGE_BMP);
image.dispose();
//
try {
java.awt.Image awtImage = Jimi.getImage(tmpPath);
if (path.endsWith(".gif"))
saveGIF(awtImage, path);
else
Jimi.putImage(awtImage, path);
} catch (Exception e) {
ProfilerPlugin.log(e);
}
(new Thread() {
public void run() {
while (!(new File(tmpPath)).delete()) {
try {
sleep(100);
} catch (InterruptedException e) {
}
}
}
}).start();
}

private void saveGIF(java.awt.Image image, String path) throws Exception {
FileOutputStream gifOS = new FileOutputStream(path);
//
try {
new GifEncoder(image, gifOS).encode();
} catch (IOException ex) {
GifEncoder encoder =
new GifEncoder(new FilteredImageSource(image.getSource(), new Web216ColorsFilter()), gifOS);
encoder.encode();
}
gifOS.close();
}



--
SY, Konstantin.
Previous Topic:[Draw2D] Adding Decorations to Figures
Next Topic:Copy & Paste to Windows clipboard
Goto Forum:
  


Current Time: Fri Jun 06 21:44:29 EDT 2025

Powered by FUDForum. Page generated in 0.03231 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top