array index
Hi! I need some help. I do proccess images and I do like that:
DataBufferByte buffer = (DataBufferByte) image.getRaster().getDataBuffer();
data = buffer.getData();
data2d = new byte[iw][ih];
it works fine.
but when I want to change the data let's say like this:
for (int i = 0; i < iw; i++) {
for (int j = 0; j < ih; j++) {
data[i * iw + j] = -1;
}
}
it goes only to 256*256 = 56536 and the rest of element are not
changed - the image is 256 * 356. Could You please what I do wrong
and is there any way out? Thanks
[607 byte] By [
screenna] at [2007-11-27 6:52:45]

# 3
I'm trying something like this as well:
buffer = new int[iw*ih];
image.getRaster().getPixels(0, 0, iw, ih, buffer);
and I got my image in the buffer, but still I can't access
anything beyond the max int 65000 something. Please help
me, this is my project and I'm running out of time :).
# 4
A Java array is indexed with an integer that has a maximum value of 2,147,483,647 - well above the size of your array. It sounds like the format of that data buffer is not what you think, and a byte array[iw * ih] does not encompass all of it or correctly interpret it. The getData() method only returns the first bank of data.
You should use
WritableRaster raster = image.getRaster();
and then use the WritableRaster set***() methods to modify the raster irrespective of the internal format.
If you must fiddle with the buffer directly, you must interpret the format with the SampleModel provided by the BufferedImage. You can either use the set***() methods to modify a given DataBuffer or use the dataType, numBands, height, and width characteristics to interpret the buffer format yourself.
# 5
The code
buffer = new int[iw * ih];
image.getRaster().getPixels(0, 0, iw, ih, buffer);
will get you the entire image and you can access all of it with an integer index. However, the data is in whatever format the BufferedImage is using. If it uses 32bpp (4 bytes RGBA), then each array element is an integer packed with four bytes of red, green, blue, and alpha values. It all depends on what SampleModel the BufferedImage is using.