I'm using Java 8 (OpenJDK 8, specifically) for a project and I need to read an image from a JPG file. Searching around got me to some similar questions at first (e.g. Read byte array into buffered image WITHOUT ImageIO and Is there a 100% Java alternative to ImageIO for reading JPEG files?), but my problem is different and the solutions there do not meet my requirements.
It turns out that the JPEGImageReader
class is still missing. (See openjdk-8: Missing JPEGImageReader functions in libjavajpeg.so) Although that bug report is for Debian, I'm using Kubuntu 14.10 and it's also affected.
Based on the report's last message, no one seems to be working on this issue at this time...
The code snippet to reproduce this error is:
// ...
BufferedImage img = null;
try {
img = ImageIO.read(new File(filename));
} catch (IOException e) {
throw new RuntimeException(e);
}
// ...
The path to the file is valid and this works normally if I use Java 1.7, but changing to 1.8 causes the following excpetion on ImageIO.read
call:
Caught UnsatisfiedLinkError: com.sun.imageio.plugins.jpeg.JPEGImageReader.initReaderIDs(Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)
I'd like help working around this problem while avoiding:
- additional dependencies on other/external libraries;
- going back to Java 1.7;
- having to rebuild from source;
- Oracle's proprietary implementation of the JDK
Working code snippets appreciated.
EDIT-1: Added point #4 to the list.
EDIT-2: Reworded a portion of the main section and added another reference.