Here you can find the source of grabRGB(ImageIcon icon)
Parameter | Description |
---|---|
icon | the image icon |
public static int[] grabRGB(ImageIcon icon)
//package com.java2s; // Distributed under the GNU Lesser General Public License import java.awt.image.*; import javax.swing.*; public class Main { /**//from w ww. j a va 2 s.com * Grabs a RGB values of the given image icon * * @param icon the image icon * @return an array of RGB values */ public static int[] grabRGB(ImageIcon icon) { int width = icon.getIconWidth(); int height = icon.getIconHeight(); int[] rgb = new int[width * height]; PixelGrabber pg = new PixelGrabber(icon.getImage(), 0, 0, width, height, rgb, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { throw new RuntimeException("Interrupted waiting for pixels!"); } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { throw new RuntimeException("Image fetch aborted or errored"); } for (int i = 0; i < rgb.length; i++) rgb[i] &= 0xffffff; return rgb; } }