is BufferedImage Empty - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

is BufferedImage Empty

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {
    public static boolean isEmpty(BufferedImage img) {
        int w = img.getWidth();
        int h = img.getHeight();
        int[] rgbs = new int[w * h];
        img.getRGB(0, 0, w, h, rgbs, 0, w);

        for (int i = 0; i < w * h; i++) {
            if (rgbs[i] != -4861744) {
                return false;
            }/*from ww w  . j a  v  a2 s  .  c  om*/
        }

        return true;
    }
}

Related Tutorials