java.lang.IllegalArgumentException: im == null?

自作多情 提交于 2020-01-16 12:00:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!