Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;

public class Main {
    static boolean isGreyscaleImage(PixelGrabber pg) {
        return pg.getPixels() instanceof byte[];
    }

    public static void main(String args[]) throws Exception {
        Image image = Toolkit.getDefaultToolkit().getImage("inFile.png");

        PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false);

        if (grabber.grabPixels()) {
            int width = grabber.getWidth();
            int height = grabber.getHeight();
            if (isGreyscaleImage(grabber)) {
                byte[] data = (byte[]) grabber.getPixels();
            } else {
                int[] data = (int[]) grabber.getPixels();
            }
        }
    }
}