From 40a7828e7c5404083d0a6adc9ecccd18dbfc96d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 7 Mar 2021 08:04:29 +0100 Subject: [PATCH] #1647 Copying to clipboard - Transparency support --- CHANGELOG.md | 2 ++ .../flash/gui/player/PlayerControls.java | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34814b785..22dbfece0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - FLA Export - mutliple FrameLabel layers - [#1636] Nullpointer exception on empty editorpane - [#1156] Rendering - 9 slice scaling (DefineScalingGrid) clipping +- [#1647] Copying to clipboard - Transparency support ## [14.1.0] - 2021-03-05 ### Added @@ -2088,6 +2089,7 @@ All notable changes to this project will be documented in this file. [#1396]: https://www.free-decompiler.com/flash/issues/1396 [#1254]: https://www.free-decompiler.com/flash/issues/1254 [#1636]: https://www.free-decompiler.com/flash/issues/1636 +[#1647]: https://www.free-decompiler.com/flash/issues/1647 [#1561]: https://www.free-decompiler.com/flash/issues/1561 [#1623]: https://www.free-decompiler.com/flash/issues/1623 [#1622]: https://www.free-decompiler.com/flash/issues/1622 diff --git a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java index 3ef3ba4b9..750e479c1 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java +++ b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java @@ -42,6 +42,8 @@ import java.awt.event.MouseMotionAdapter; import java.awt.font.TextAttribute; import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.HashMap; @@ -587,20 +589,24 @@ public class PlayerControls extends JPanel implements MediaDisplayListener { return; } - //Copy to clipboard does not support transparency - BufferedImage newImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); - Graphics2D g = newImage.createGraphics(); - g.setColor(display.getBackgroundColor()); - g.fillRect(0, 0, img.getWidth(), img.getHeight()); - g.drawImage(img, 0, 0, null); - g.dispose(); + //If the image contains transparency, + //exception stack trace is printed to stderr in java internals + //see https://stackoverflow.com/questions/59140881/error-copying-an-image-object-to-the-clipboard + //we handle this by ignoring System.err + final PrintStream originalErr = System.err; + System.setErr(new PrintStream(new OutputStream() { + @Override + public void write(int b) throws IOException { - TransferableImage trans = new TransferableImage(newImage); + } + })); + TransferableImage trans = new TransferableImage(img); Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); c.setContents(trans, new ClipboardOwner() { @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { } }); + System.setErr(originalErr); //Reset system.err back to normal state } }