I'm using something along the lines of this to do a (naive, apparently) check for the color space of JPEG images:
import java.io.*;
import java.awt.color.*;
import java.awt.image.*;
import javax.imageio.*;
class Test
{
    public static void main(String[] args) throws java.lang.Exception
    {
        File f = new File(args[0]);
        if (f.exists())
        {
            BufferedImage bi = ImageIO.read(f);
            ColorSpace cs = bi.getColorModel().getColorSpace();
            boolean isGrayscale = cs.getType() == ColorSpace.TYPE_GRAY;
            System.out.println(isGrayscale);
        }
    }
}
Unfortunately this reports false for images that (visually) appear gray-only. 
What check would do the right thing?
 
     
     
    