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

后端 未结 1 1463
囚心锁ツ
囚心锁ツ 2020-12-29 07:37

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         


        
相关标签:
1条回答
  • 2020-12-29 08:36

    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 give a warning and ignore the ICC profile in this case.
    • 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.
    0 讨论(0)
提交回复
热议问题