Take the 2-minute tour ×

I´m trying to copy a png file to clipboard within a program and maintain its alpha channel when pasted in another program (e.g. ms office, paint, photoshop). The problem is, that the alpha channel turns black in most of the programs. I've been searching the web for hours now and can't find a solution. The Code I'm using:


public static void setClipboard(Image image) {
    ImageSelection imgSel;
if (OSDetector.isWindows()) {
    imgSel = new ImageSelection(image);
} else {
    imgSel = new ImageSelection(getBufferedImage(image));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);

Is there any way to maintain the alpha channel in Java? I've tried converting the png to BufferedImage, Image, etc. and the pasting it to the clipboard, but nothing works.

share|improve this question
Have you seen this: stackoverflow.com/questions/665406/… ? –  NullUserException Jan 23 '13 at 21:04
Paint does not support transparency, so don't expect it to work there. Might be the case with other programs too. –  user1615903 Jan 24 '13 at 8:04
@user1615903: Are you certain about that? Well, it doesn´t show transparency in Photoshop either: Background is black and is supposed to be transparent. –  Chris Jan 25 '13 at 12:27
@NullUserException: Yes, I had already found that, thanks. the reason why I didn´t pay further attention to that thread is, that 1. the picture to be loaded into clipboard already has a transparent layer and 2. if I would e.g. turn transparent to black as an intermediate step and then turn black to transparent again, it would also turn the black parts of the picture transparent that are supposed to be black. Did I get that right? –  Chris Jan 25 '13 at 12:34
Does anybody have an idea how to solve this problem? It is rather annoying and I just cant find an adequate solution to it. Meanwhile I have also tried working with DataFlavor.javaFileListFlavor, which works fine for copying Clipboard Images to MS Office, but doesnt work for photoshop and MS Paint. –  Chris Feb 21 '13 at 11:44
add comment

Your Answer



Browse other questions tagged or ask your own question.