Tim
Tim

Reputation: 13258

RenderedImage -> RGB values

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] = 120; // 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!

Upvotes: 2

Views: 1101

Answers (2)

trashgod
trashgod

Reputation: 205785

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);
}

Upvotes: 0

Abboq
Abboq

Reputation: 1101

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.

Upvotes: 2

Related Questions