Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy chart to clipboard IOException (Windows) #182

Closed
lynnskii opened this issue Nov 5, 2020 · 1 comment
Closed

Copy chart to clipboard IOException (Windows) #182

lynnskii opened this issue Nov 5, 2020 · 1 comment

Comments

@lynnskii
Copy link

lynnskii commented Nov 5, 2020

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.

@jfree
Copy link
Owner

jfree commented Nov 10, 2020

Thanks for the report. I presume the the JDK on Windows tries to convert the image to JPEG format? I don't get any exception on MacOS. Nevertheless, I've changed the BufferedImage type for the next release (v.1.5.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants