图像复制到剪贴板不工作在Linux(Java的AWT和放大器; SWT) [英] Copy Image to Clipboard not working on Linux (Java AWT & SWT)

查看:197
本文介绍了图像复制到剪贴板不工作在Linux(Java的AWT和放大器; SWT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发Eclipse RCP应用程序,其中包括JFreeChart的。它的特点之一是将图形复制到剪贴板,以便将它们粘贴到其他应用程序,但它不能在Linux上使用,

有一个<一个href=\"http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet282.java\"相对=nofollow> SWT样品在这里你可以找到一个片段,不能在Linux下正常工作。

在另一方面的JFreeChart实现了这个在AWT为:

 剪贴板systemClipboard
            = Toolkit.getDefaultToolkit()getSystemClipboard();
    插图插图=的getInsets();
    INT W =的getWidth() - insets.left - insets.right;
    INT H =的getHeight() - insets.top - insets.bottom;
    ChartTransferable选择=新ChartTransferable(this.chart,W,H,
            getMinimumDrawWidth(),getMinimumDrawHeight(),
            getMaximumDrawWidth(),getMaximumDrawHeight(),真);
    systemClipboard.setContents(选择,NULL);

Howewer两个例子不能在Linux上64位。有没有实现呢??办法

在此先感谢!

编辑:

code。该图形的JFreeChart复制到一个文件,但不进剪贴板

 最后org.eclipse.swt.dnd.Clipboard剪贴板=新org.eclipse.swt.dnd.Clipboard(menu​​.getDisplay());
                    插图插图= source.getInsets();
                    INT W = source.getWidth() - insets.left - insets.right;
                    INT H = source.getHeight() - insets.top - insets.bottom;
                    ChartTransferable选择=新ChartTransferable(源
                            .getChart(),W,H,source.getMinimumDrawWidth(),source.getMinimumDrawHeight(),源
                            .getMaximumDrawWidth(),source.getMaximumDrawHeight(),真);                    图像的图像=新的图像(menu​​.getDisplay(),ImageUtils.convertToSWT(selection.getBufferedImage()));
                    如果(形象!= NULL){
                        ImageLoader的ImageLoader的=新ImageLoader的();
                        imageLoader.data =新的ImageData [] {image.getImageData()};
                        imageLoader.save(/ tmp目录/ graph.jpg,SWT.IMAGE_JPEG); //失败
                        ImageTransfer imageTransfer = ImageTransfer.getInstance();
                        clipboard.setContents(新的对象[] {image.getImageData()},
                                新的过户[] {} imageTransfer,DND.CLIPBOARD | DND.SELECTION_CLIPBOARD);
                    }


解决方案

试试这个code:

 的JFreeChart图表= YOUR_CHART_HERE;
ChartComposite chartComposite =新ChartComposite(壳,SWT.NONE,图表,真实);图像的图像=新的图像(Display.getDefault(),chartComposite.getBounds());
GC GC =新的GC(图片);
chartComposite.print(GC);
gc.dispose();ImageTransfer imageTransfer = ImageTransfer.getInstance();
clipboard.setContents(新的对象[] {image.getImageData()},新的过户[] {imageTransfer});

I am developing an Eclipse RCP Application which includes JFreeChart. One of its features is to copy graphs to the clipboard in order to paste them into other applications but it does not work on Linux,

There is a SWT sample where you can find a snippet that does not work in Linux.

On the other hand JFreeChart implemented this on AWT as:

Clipboard systemClipboard
            = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = getInsets();
    int w = getWidth() - insets.left - insets.right;
    int h = getHeight() - insets.top - insets.bottom;
    ChartTransferable selection = new ChartTransferable(this.chart, w, h,
            getMinimumDrawWidth(), getMinimumDrawHeight(),
            getMaximumDrawWidth(), getMaximumDrawHeight(), true);
    systemClipboard.setContents(selection, null);

Howewer both examples fail on Linux 64bit. Is there a way to implement it??

Thanks in advance!

EDIT:

Code that copy the JFreeChart graphic into a file but not into the Clipboard

final org.eclipse.swt.dnd.Clipboard clipboard = new org.eclipse.swt.dnd.Clipboard(menu.getDisplay());
                    Insets insets = source.getInsets();
                    int w = source.getWidth() - insets.left - insets.right;
                    int h = source.getHeight() - insets.top - insets.bottom;
                    ChartTransferable selection = new ChartTransferable(source
                            .getChart(), w, h, source.getMinimumDrawWidth(), source.getMinimumDrawHeight(), source
                            .getMaximumDrawWidth(), source.getMaximumDrawHeight(), true);

                    Image image = new Image(menu.getDisplay(),ImageUtils.convertToSWT(selection.getBufferedImage()));
                    if (image != null) {
                        ImageLoader imageLoader = new ImageLoader(); 
                        imageLoader.data = new ImageData[] { image.getImageData() }; 
                        imageLoader.save("/tmp/graph.jpg", SWT.IMAGE_JPEG); // fails 
                        ImageTransfer imageTransfer = ImageTransfer.getInstance();
                        clipboard.setContents(new Object[]{image.getImageData()}, 
                                new Transfer[]{imageTransfer}, DND.CLIPBOARD | DND.SELECTION_CLIPBOARD);
                    }

解决方案

Try this code:

JFreeChart chart = YOUR_CHART_HERE;
ChartComposite chartComposite = new ChartComposite(shell, SWT.NONE, chart, true);

Image image = new Image(Display.getDefault(), chartComposite.getBounds());
GC gc = new GC(image);
chartComposite.print(gc);
gc.dispose();

ImageTransfer imageTransfer = ImageTransfer.getInstance();
clipboard.setContents(new Object[] {image.getImageData()}, new Transfer[]{imageTransfer});

这篇关于图像复制到剪贴板不工作在Linux(Java的AWT和放大器; SWT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆