get Image Row Rgba 8 - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

get Image Row Rgba 8

Demo Code


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

public class Main {
    public static int[] getRowRgba8(BufferedImage im, int rown, int[] buf) {
        int pixels = im.getWidth();
        int samples = pixels * 4;
        if (buf == null || buf.length < samples)
            buf = new int[samples];
        im.getRGB(0, rown, pixels, 1, buf, 0, pixels);
        for (int p = pixels - 1, s = samples - 1; p >= 0; p--) {
            int v = buf[p];
            buf[s--] = ((v >> 24) & 0xff); // A
            buf[s--] = (v & 0xff); // B
            buf[s--] = ((v >> 8) & 0xff); // G
            buf[s--] = ((v >> 16) & 0xff); // R
        }/*from   ww w .  jav  a 2  s.co  m*/
        return buf;
    }
}

Related Tutorials