Forums Register Login

A question for JAI users

+Pie Number of slices to send: Send
Hi.
I am using JAI for an image processing application. I need to open Tiff image files, process them and then save the resulting image in a TIFF file.

The code I am using just to open the pca.tif image file and save the negative image is:

import javax.media.jai.*;
import java.awt.image.*;

class Negative{

public static void main(String arg[]){

PlanarImage orIm;
SampleModel sm;
DataBuffer data;
int[][][] imageArray;
int h,w,bands;

orIm = JAI.create("fileload","C:/sample.tif");
w = orIm.getWidth();
h = orIm.getHeight();
bands = orIm.getNumBands();

sm = orIm.getSampleModel();
data = orIm.getData().getDataBuffer();
imageArray = new int[bands][w][h];
// get pixel values
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++)
imageArray[b][i][j]=sm.getSample(i,j,b,data);
}
}

// invert pixel values
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++){
imageArray[b][i][j]=255 - imageArray[b][i][j];
}
}
}

// set new pixel values to original image
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++)
sm.setSample(i,j,b,imageArray[b][i][j],data);
}
}

RenderedOp op = JAI.create("filestore",orIm,"negSample.tif","tiff");

}
}

So far so good, but when I am using the above code to load the negative image file in order to produce the original I get the message:

java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!

The bizarre is that if I choose to open the negSample.tif image on Photoshop and then overwrite it leaving the name unchanged my program works fine!

Any suggestions?
Thanks in advance
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1075 times.
Similar Threads
Help... Urgent.. PLEASE... Applet Code....
Help... Urgent.. PLEASE... Applet Code....
How to overcome OutOfMemory exception?
How to overcome OutOfMemory error?
JPEG Image problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:47:08.