Java BufferedImage to RGB getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels)

Here you can find the source of getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels)

Description

A convenience method for getting ARGB pixels from an image.

License

Apache License

Parameter

Parameter Description
image a BufferedImage object
x the left edge of the pixel block
y the right edge of the pixel block
width the width of the pixel arry
height the height of the pixel arry
pixels the array to hold the returned pixels. May be null.

Return

the pixels

Declaration

public static int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.image.*;

public class Main {
    /**/*w w w .j a v a 2 s  .  c om*/
     * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance
     * penalty of BufferedImage.getRGB unmanaging the image.
      * @param image   a BufferedImage object
      * @param x       the left edge of the pixel block
      * @param y       the right edge of the pixel block
      * @param width   the width of the pixel arry
      * @param height  the height of the pixel arry
      * @param pixels  the array to hold the returned pixels. May be null.
      * @return the pixels
      * @see #setRGB
      */
    public static int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
        int type = image.getType();
        if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
            return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels);
        return image.getRGB(x, y, width, height, pixels, 0, width);
    }
}

Related

  1. getRGB(BufferedImage img)
  2. getRgbFromImage(BufferedImage image)
  3. getRGBPixels(BufferedImage img)
  4. imageToMatrix(BufferedImage image)