1

画像をクリップボードにコピーして、次のコード スニペットを使用して gimp に貼り付けようとしました。

BufferedImage bi = new BufferedImage(board.getAmount()*16,16,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();

Color[] colors = board.getColors();

for (int loop = 0; loop < board.getAmount(); loop++) {
    g2d.setColor(colors[loop]);
    g2d.fill(new Rectangle(16*loop,0,16,16));
}



ImageSelection is = new ImageSelection(bi);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(is, null);

とにかく、理論的にはすべてがうまくいくはずです。エラーは発生しませんでしたが、画像を貼り付けようとしても何も起こりません。

これは 2 つの異なる Linux マシンで実行されましたが、どちらも機能しませんでした。その後、学校に来て、Windows で同じコードを試してみたところ、うまくいきました。

だから私の本当の質問は、open-jdk、またはJava 1.7と関係があるのでしょうか、それともLinuxの問題ですか? どうすれば修正できますか?

4

2 に答える 2

0

次のページが役に立つと思います: http://www.java2s.com/Code/Java/2D-Graphics-GUI/SendingImageObjectsthroughtheClipboard.htm

画像をクリップボードにコピーするには、次の行を検討してください。

final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
label.setTransferHandler(new ImageSelection());
...
TransferHandler handler = label.getTransferHandler();
handler.exportToClipboard(label, clipboard, TransferHandler.COPY);
于 2012-05-09T15:01:50.400 に答える
0

I had the same problem, and found this to work:

final Clipboard clipboard = frame.getToolkit().getSystemSelection();

...then continue using that as a regular clipboard. The "system selection" allows you to change what the window manager thinks is selected, and is therefore "on the clipboard".

I'm not sure what the best way to detect whether system selection or system clipboard should be used, but it looks like Windows will return null for getSystemSelection, so that can be used as a test.

于 2014-01-22T21:37:12.987 に答える