0

I need to read an image, resize it and then save it. However, when reading a very large image, ImageIO#read() returns null.

FileInputStream f = new FileInputStream(imagePath);     
image = ImageIO.read(f);

How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Post your entire stack trace here, and let's see the root cause of the exception. Just a suggestion: avoid a chaining call like `request.getSession().getServletContext().getRealPath(imageUrl)` for exactly the reason that you're experiencing now. Break it up into smaller calls so you can narrow the source of your issues better – kolossus Dec 18 '12 at 08:17
  • [ImageIO#read(InputStream)](http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html#read(java.io.InputStream)) returns `null` if no registered reader was able to able to decode the image data from the inputstream. Are yousure youwas able to read smaller images of the same format as the large one? – A4L Aug 15 '13 at 12:49

1 Answers1

1

Image I/O has built-in support for GIF, PNG, JPEG, BMP, and WBMP only. Are you trying to load any other type of image than these. See Reading/Loading an Image for details.

You may check the list of registered readers using ImageIO.getReaderFormatNames(). For me it lists [BMP, bmp, jpg, JPG, wbmp, jpeg, png, JPEG, PNG, WBMP, GIF, gif]

Kuldeep Jain
  • 8,409
  • 8
  • 48
  • 73