IllegalArgumentException: Numbers of source Raster bands and source color space components do not match For a color image Exception

青春壹個敷衍的年華 提交于 2020-01-10 10:15:32

问题


The above answer that someone has suggest, converts my colored image to a black and white one. So it's not appropriate for my question.

File file = new File("path");          
BufferedImage bufferedImage = ImageIO.read( file );

here is the code and below is the image. Download the image and save in your pc. And try to run the above code with a correct value of path, it will throw an exception in the topic

Download image: https://skydrive.live.com/?cid=19547371C4F3B839&id=19547371C4F3B839%21105

Simply if someone can obtain a java.awt.image.BufferedImage object from the image given that's enough (should not convert the image to gray scale one).

You are a genius if you can answer this :D. Plz help.


回答1:


There's nothing wrong with your code here. I could read your image using my JPEGImageReader plugin for ImageIO. This image reader tries to be lenient about JPEG errors, and is slightly more capable than the standard Java JPEGImageReader.

However, your JPEG file seems to have a number of problems so it can't be read 100%:

  • First, the ICC color profile in the image has 4 color components, while the image data has only 3 color components (this is causing the exception you see). The root cause is probably bad conversion software. Use ExifTool or similar software to have a look at the metadata for further investigation. My reader will simply ignore the ICC profile.
  • Second, the JPEG stream ends prematurely (missing EOI). You'll notice that there's some garbage pixels at the lower right of the image. There's nothing you can do about that, except getting the original image (well, actually, the image contains a thumbnail and the thumbnail is undamaged; you could try to recreate the data from that if you really need to). The image returned from my reader is consistent with images read by native software.


来源:https://stackoverflow.com/questions/18351583/illegalargumentexception-numbers-of-source-raster-bands-and-source-color-space

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