Getting the Color Model of an Image
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.PixelGrabber;
import javax.swing.ImageIcon;
public class Main {
public static void main(String[] argv) throws Exception {
Image image = new ImageIcon("a.png").getImage();
if (image instanceof BufferedImage) {
BufferedImage bimage = (BufferedImage) image;
System.out.println(bimage.getColorModel().getNumColorComponents());
}
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {
pg.grabPixels();
} catch (InterruptedException e) {
}
ColorModel cm = pg.getColorModel();
System.out.println(cm.getNumColorComponents());
}
}
Related examples in the same category