Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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());
    }
}