#1647 Copying to clipboard - Transparency support

This commit is contained in:
Jindra Petřík
2021-03-07 08:04:29 +01:00
parent 004e2ecdfd
commit 40a7828e7c
2 changed files with 16 additions and 8 deletions

View File

@@ -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

View File

@@ -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
}
}