Hey, Whenever I try to get an object ImageInputStreamusing ImageIO.createImageInputStream, it just returns nullwithout exceptions, warnings or errors. I tried passing different types of data to a function, simple Fileand InputStream, but both returned null. The documentation states that if no suitable ImageInputStreamSpione is found, the function will return null, but the file is a standard JPEG format, and, of course, does Java come with a service provider for that format out of the box? Thank you for your time.
private BufferedImage readImage( File source ) {
final int imageIndex = 0;
BufferedImage image = null;
try {
Iterator readers =
ImageIO.getImageReaders( source );
ImageReader reader = (ImageReader) readers.next();
ImageInputStream iis = ImageIO.createImageInputStream( source );
reader.setInput( iis, true );
image = reader.read( imageIndex );
} catch ( Exception exception ) {
exception.printStackTrace();
System.exit( -1 );
}
return image;
}
source
share