问题
I actually get the input source from PostgreSQL. The table column type is bytea. I want to convert the byte back to original image.
BuffredImage bImageFromConvert = ImageIo.read(new ByteArrayInputStream(rsvalue.getBytes(10)));
ImageIO.write(bImageFromConvert, "jpg", new File("D:\\"+ rsvalue.getString(2) +".jpg"));
The error as below :
Exception in thread "main" java.lang.IllegalArgumentException: im == null!
at javax.imageio.ImageIO.write(ImageIO.java:1457)
at javax.imageio.ImageIO.write(ImageIO.java:1521)
at my.lincdoc.controller.ProposalController.RetrieveProposalForm(ProposalController.java:66)
at my.lincdoc.common.App.main(App.java:16)
Anyone can help me ?
回答1:
The docs for ImageIO.read state:
If no registered ImageReader claims to be able to read the resulting stream, null is returned.
And if bImageFromConvert
is null, you'll get the exception you've shown. So that's almost certainly what's happening. You should look at the data returned from rsvalue.getBytes(10)
- see whether it's incomplete, corrupt or something similar. A starting point would be to write it to a file and see whether you can open it using a picture viewer.
来源:https://stackoverflow.com/questions/8112197/java-lang-illegalargumentexception-im-null