Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:08:26+00:00 2026-06-08T07:08:26+00:00

Apologies for the somewhat vague title, I can’t work out what the keywords are

  • 0

Apologies for the somewhat vague title, I can’t work out what the keywords are here. The setup’s quite simple, I’m opening an image with

ImageIO.read(new File(filename));

This works for most files, however for one I get an IllegalArgumentException with the detail: "numbers of source Raster bands and source color space components do not match". This image was obtained via wget on a valid Flickr URL, and I’ve used other images obtained this way, so the method for obtaining images seems sound in principle. I’m not sure what’s causing the exception.

A workaround would be more than acceptable – I’m not fussed with using ImageIO in particular, and the image looks fine visually. I just need to get it being read without Java freaking out!

Here’s the image in question, in case it’s of any use:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:08:28+00:00Added an answer on June 8, 2026 at 7:08 am

    So I was having this same issue and found that the image was gray-scale and that the default ImageIO.read implementation was not figuring that out because the image metadata wasn’t quite as expected. I wrote a work around that retries the load as ‘BufferedImage.TYPE_BYTE_GRAY’ if it fails the main load.

                Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);
    
            Exception lastException = null;
            while (iter.hasNext()) {
                ImageReader reader = null;
                try {
                    reader = (ImageReader)iter.next();
                    ImageReadParam param = reader.getDefaultReadParam();
                    reader.setInput(stream, true, true);
                    Iterator<ImageTypeSpecifier> imageTypes = reader.getImageTypes(0);
                    while (imageTypes.hasNext()) {
                        ImageTypeSpecifier imageTypeSpecifier = imageTypes.next();
                        int bufferedImageType = imageTypeSpecifier.getBufferedImageType();
                        if (bufferedImageType == BufferedImage.TYPE_BYTE_GRAY) {
                            param.setDestinationType(imageTypeSpecifier);
                            break;
                        }
                    }
                    bufferedImage = reader.read(0, param);
                    if (null != bufferedImage) break;
                } catch (Exception e) {
                    lastException = e;
                } finally {
                    if (null != reader) reader.dispose();               
                }
            }
            // If you don't have an image at the end of all readers
            if (null == bufferedImage) {
                if (null != lastException) {
                    throw lastException;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies for the somewhat vague title, I'll try explain more here. Currently, I have
Apologies for the somewhat unclear question - couldn't think of a better way of
Apologies for the poor question title. I have two tables, jobs and Persons-Jobs. Jobs
Apologies, I'm new to ASP.NET MVC. :) I'm unsure if this is simple a
Apologies, somewhat confused Python newbie question. Let's say I have a module called animals.py
Apologies for the big block 'o' text, but I'm somewhat of a beginner having
Apologies for the title, I am unsure how to express my problem... I have
(apologies for the somewhat lengthy intro) During development of an application which prefaults an
I am somewhat new to Jquery but I feel complete failure here at not
Apologies if this is a very simple question; I don't use XSLT very much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.