Java Utililty Methods BufferedImage Pixel

List of utility methods to do BufferedImage Pixel

Description

The list of methods to do BufferedImage Pixel are organized into topic(s).

Method

voidextractFromPixeldata(short[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length)
extract From Pixeldata
for (int y = 0, i = off, imax = off + length; y < columns && i < imax; y++) {
    for (int j = y * stride; j < imax && i < imax; j++, i++) {
        if ((pixeldata[j] & mask) != 0) {
            ovlyData[i >>> 3] |= 1 << (i & 7);
StringgetRandomPixel(final String fileName)
get Random Pixel
if (!fileName.equals(file)) {
    img = ImageIO.read(new File(fileName));
    file = fileName;
return String.format("#%06X", (0xFFFFFF
        & img.getRGB((int) (Math.random() * img.getWidth()), (int) (Math.random() * img.getHeight()))));
ImageimageFromIntArray(int[] pixels, int w, int h)
Build an image from a pixel array.
Image img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pixels, 0, w));
return img;
int[]pixels(BufferedImage image)
pixels
return image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
byte[]pixelsb(BufferedImage image)
pixelsb
DataBuffer dataBuffer = image.getRaster().getDataBuffer();
if (dataBuffer instanceof DataBufferByte) {
    return ((DataBufferByte) dataBuffer).getData();
throw new IllegalArgumentException("image is instanceof " + dataBuffer.getClass());
int[][]pixelsFromBufferedImage(final BufferedImage image)
pixels From Buffered Image
int[][] pixArr = new int[image.getWidth()][image.getHeight()];
for (int x = 0; x < image.getWidth(); x++) {
    for (int y = 0; y < image.getHeight(); y++) {
        pixArr[x][y] = image.getRGB(x, y);
return pixArr;
Objectpixelsg(BufferedImage image)
http://stackoverflow.com/questions/4386446/problem-using-imageio-write-jpg-file/4388542#4388542
PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true);
try {
    pg.grabPixels();
} catch (InterruptedException e) {
    e.printStackTrace();
return pg.getPixels();
BufferedImagepixelsToImage(int[][] pixels)
pixels To Image
if (pixels == null) {
    return null;
int w = pixels.length;
if (w > 0) {
    int h = pixels[0].length;
    if (h > 0) {
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
...
voidsetRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels)
A convenience method for setting ARGB pixels in an image.
int type = image.getType();
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
    image.getRaster().setDataElements(x, y, width, height, pixels);
else
    image.setRGB(x, y, width, height, pixels, 0, width);
int[]toRgbPixels(BufferedImage image)
to Rgb Pixels
if (image.getData().getDataBuffer() instanceof DataBufferInt) {
    return ((DataBufferInt) image.getData().getDataBuffer()).getData();
} else {
    return image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());