Copy to Clipboard IOException (ARGB channel no longer supported for JPEGs)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
lynnskii
Posts: 5
Joined: Wed Apr 20, 2016 8:37 am
antibot: No, of course not.

Copy to Clipboard IOException (ARGB channel no longer supported for JPEGs)

Post by lynnskii » Fri May 24, 2019 11:37 pm

I'm in the process of migrating my applications to OpenJDK 11, I've discovered that copying a ChartPanel image to the WIndows clipboard now gives an IOException:

java.io.IOException: Registered service providers failed to encode BufferedImage@228e6026: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 765 height = 420 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0 to image/jpeg
at java.desktop/sun.awt.datatransfer.DataTransferer.imageToStandardBytesImpl(DataTransferer.java:1799)
at java.desktop/sun.awt.datatransfer.DataTransferer.imageToStandardBytes(DataTransferer.java:1713)
at java.desktop/sun.awt.windows.WDataTransferer.imageToPlatformBytes(WDataTransferer.java:353)
at java.desktop/sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:855)
at java.desktop/sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:220)
at java.desktop/sun.awt.windows.WClipboard.setContentsNative(WClipboard.java:83)
at java.desktop/sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:105)
at org.jfree.chart.ChartPanel.doCopy(ChartPanel.java:2702)

Have done some research, it seems that the alpha channel of the JPEG image is no longer supported in the OpenJDK implementation.

I've tracked it down to org.jfree.chart.ChartTransferable.ChartTransferable.createBufferedImage(…)
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

If BufferedImage.TYPE_INT_ARGB is replaced by BufferedImage.TYPE_INT_RGB, it works. Not sure if there are any other places with similar issues.

Here are some links from my research:
https://github.com/fesch/Structorizer.D ... issues/685
Apparently, the clipboard converts the image into JPG format instead of PNG as the menu item promises. As you would expect, the stack trace vanishes if the image type BufferedImage.TYPE_INT_RGB is used to prepare the image for transfer. The visual result doesn't differ.

https://bugs.openjdk.java.net/browse/JDK-8176556
https://bugs.openjdk.java.net/browse/JDK-8204188
JDK-8204187 removed support for ARGB channel for JPEG. Test uses ARGB input to encode JPEG image and we get IOException.

Post Reply