|
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  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03231 seconds