BufferedImage to Pixel Matrix - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Pixel

Description

BufferedImage to Pixel Matrix

Demo Code


//package com.java2s;
import java.awt.image.BufferedImage;

public class Main {
    public static int[][] toPixelMatrix(BufferedImage G) {
        int m = G.getWidth();
        int n = G.getHeight();
        int[][] pixelMatrix = new int[m][n];

        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                //                 Getting negatives with JavaFX Image to BufferedImage??
                pixelMatrix[i][j] = Math.abs(G.getRGB(i, j));
            }//  w  w w  .j  av  a  2 s.c  om
        }

        return pixelMatrix;
    }
}

Related Tutorials