开发者

RenderedImage -> RGB values

开发者 https://www.devze.com 2022-12-18 22:30 出处:网络
I use an interface of RenderedImage for reading a tif image. How can I get all rgb values of this picture in a 2d-Array like this:

I use an interface of RenderedImage for reading a tif image. How can I get all rgb values of this picture in a 2d-Array like this:

red[0][128] = 12开发者_运维技巧0; // means x=0, y=128, red value = 120
// the value 120 is the value I have to determine (and oall other rgb values)!

Does anyone know this?

Thanks a lot for your help!


getData() returns a Raster, which has a getData() method.

Can you call YourRenderedImage.getData().getPixel(int x, int y, int iArray[]) to get your RGB values?

JavaDoc: Returns the samples in an array of int for the specified pixel. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds.

Raster.getPixel() - JavaDoc

I believe the elements returned by the int array represent: Red, Green, Blue, Alpha, and Hex key, but I don't know for sure.


Like Abboq, I thought you wanted to traverse the Raster, which should work. Alternatively, you might be able to use BandSelect to get each of the three bands you want.

RenderedImage[] dst = new RenderedImage[3];
int[] bandIndices = new int[1];
for (int i = 0; i < 3; i++) {
    bandIndices[0] = i;
    pb = new ParameterBlock();
    pb.addSource(src);
    pb.add(bandIndices);
    dst[i] = (RenderedImage) JAI.create("bandSelect", pb);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号