java.lang.ArrayIndexOutOfBoundsException : creation image impossible !
Bonjour,
J'obtiens une erreur d'exception qui ne correspond pas a la realite :
Citation:
Can't display: java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
En effet J'ai initialise l'image avec width=355 et height=245 comme vous pouvez le voir sur le debut de la methode qui pose probleme :
Code:
1 2 3 4 5 6 7 8 9
|
public BufferedImage CreatePicture(int wi,int ho,int minX,int minY,int int_slice)
{
try
{
ScanImage=null;
System.out.println("Viewer:CreatePicture beginning");
ScanImage = new BufferedImage(wi,ho,BufferedImage.TYPE_INT_RGB); |
La suite est un peu complexe mais simplemement extraire l'image d'un dataset :
Code:
1 2 3 4 5 6 7
|
//Extract the image from the dataset
DataInputStream dis = new DataInputStream(new
FileInputStream(str_datasetPath));
dis.skipBytes(24+int_slice*int_nbByteImage);//24 stands for the header 6 short + 3float
byte[] byte_voxel = new byte[int_nbByteImage];
dis.readFully(byte_voxel); |
Le reste du code est la creation de l\image proprement dite, comme vous pouvez le voir l'image va jusquq ces limites : ho et wi*2 mais avec un pas de x=2 ce qui ne depasse pas les limites du tableaux wi.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
for(int y=0; y<ho; y++)
{
int i = (y+minY)*widthInVoxels*2;
for(int x=0; x<wi*2; x+=2)
{
short sht_voxel = (short)((((byte_voxel[i+x+minX]&
0x000000ff) << 8) | (byte_voxel[i+x+1+minX]& 0x000000ff))-minDensityValue&
0x0000ffff);
sht_voxel = (short)(sht_voxel*255/int_ColorRange);
//convert the voxel value into a range from 0 to 255
System.out.println("Viewer:CreatePicture test at x="+x);
ScanImage.setRGB((x+minX)/2,y+minY, sht_voxel << 16 | sht_voxel
<< 8 | sht_voxel);
}
} |
Malheureusement a x=622 j'obtiens l'exception. Comme x va de 2 en 2 cela correspond a une taille de tableau de 622/2=311. or mon tableau a ete initialise a 355 comme on peut le voir a ma premiere ligne de code.
C'est a cause de ca que je bloque : j'ai remarque que x va jusqua 702 ce qui correspond <= a la taille du tableau 355 car 702/2=351.
Voici le reste du code correspondant a la gestion d'exception :
Code:
1 2 3 4 5 6 7
|
}catch(Exception e){System.out.println("Can't display: " +
e);}
// return the image
System.out.println("Viewer:CreatePicture finishing ok");
return ScanImage;
} |
J'espere obntenir de l'aide merci !