From 9e7db1ce64abd750444aceb6bb2a67c35ae933b6 Mon Sep 17 00:00:00 2001 From: matthew16550 Date: Wed, 8 Sep 2021 14:51:40 +1000 Subject: [PATCH] Fix copy to clipboard on Mac. The previous code `Toolkit.getDefaultToolkit().createImage()` does not read the image file into memory but Clipboard.setContents() on Mac seems to need an image that is already in memory. --- src/net/sourceforge/plantuml/swing/ImageWindow.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/net/sourceforge/plantuml/swing/ImageWindow.java b/src/net/sourceforge/plantuml/swing/ImageWindow.java index f1d685dcb..a86940ce7 100644 --- a/src/net/sourceforge/plantuml/swing/ImageWindow.java +++ b/src/net/sourceforge/plantuml/swing/ImageWindow.java @@ -388,10 +388,14 @@ class ImageWindow extends JFrame { if (generatedImage == null) { return; } - final File png = generatedImage.getPngFile(); - final Image image = Toolkit.getDefaultToolkit().createImage(png.getAbsolutePath()); - final ImageSelection imgSel = new ImageSelection(image); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null); + try { + final File png = generatedImage.getPngFile(); + final Image image = ImageIO.read(png); + final ImageSelection imgSel = new ImageSelection(image); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null); + } catch (IOException e) { + e.printStackTrace(); + } } public SimpleLine getSimpleLine() {