writableRaster

时间:2015-11-18 15:19:25

标签: java raster pixels

在writableRaster类中,有一个方法:

public void setPixels(int x,
             int y,
             int w,
             int h,
             int[] iArray)

iArray中的哪个位置应存储有关像素的信息 对于像素:233(r)244(g)10(b),它应该如何存储在iArray中?

iArray[0] = 233iArray[1] = 244iArray[2] = 10 还是iArray[0] = [24424410]

1 个答案:

答案 0 :(得分:1)

简短回答,应该是iArray[0] = 233, iArray[1] = 244, iArray[2] = 10而不是iArray[0] = [24424410]

但是,数据量取决于WritableRaster支持的内容。考虑以下示例,我们检索两个WriteableRaster的{​​{1}};一个包含RGB数据和另一个ARGB数据。如果我们检索像素值,我们可以看到该数组的RGB数据长度为3,ARGB数据长度为4。

<强>代码:

BufferedImages

<强>输出:

public static void main(String[] args) {
    BufferedImage rgbImage = new BufferedImage(8, 8,
            BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();

    BufferedImage argbImage = new BufferedImage(8, 8,
            BufferedImage.TYPE_INT_ARGB);
    WritableRaster argbRaster = argbImage.getRaster();

    rgbImage.setRGB(0, 0, new Color(255, 125, 1, 16).getRGB());
    argbImage.setRGB(0, 0, new Color(255, 125, 1, 16).getRGB());

    int[] rgb = rgbRaster.getPixel(0, 0, (int[]) null);
    int[] argb = argbRaster.getPixel(0, 0, (int[]) null);
    System.out.print("rgb:");
    for (int i = 0; i < rgb.length; ++i)
        System.out.print(" "+rgb[i]);

    System.out.print("\nargb:");
    for (int i = 0; i < argb.length; ++i)
        System.out.print(" "+argb[i]);
}