Erreur de "ArrayIndexOutOfBoundsException:"
Bonjour ,
j' essaye de mettre une petite image dans une grande, pour cela je colle le tableau de l'une dans l'autre,
j'ai une erreur à la compilation, ça fait un moment que je suis deçue je ne sais plus quoi faire...:?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 255
at Bitmap.creerIncurstation(bitmap.java:30)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
import java.io.*;
import java.util.Scanner;
public class Bitmap {
Scanner sc = new Scanner(System.in);
int[][][]data;
String nom;
ImageExterne ie;
Bitmap(String n) throws IOException, FileNotFoundException { // constructeur pour les images lues
this.ie=new ImageExterneLue(n);
this.nom=n;
this.data=((ImageExterneLue)ie).getTableau();
}
Bitmap(int largeur, int hauteur){ // constructeur pour les images créés
this.data=new int[largeur][hauteur][3];
for(int x=0;x<this.data.length;x++){
for(int y=0;y<this.data[0].length;y++){
this.data[x][y][0]=250;
this.data[x][y][1]=250;
this.data[x][y][2]=250;
}
}
this.nom=null;
this.ie=new ImageExterneCree(this.data);
}
Bitmap creerIncurstation(Bitmap ImgLue){
for(int x=0;x<this.data.length;x++){
for(int y=0;y<this.data[0].length;y++){
this.data[x][y][0]=ImgLue.data[x][y][0];
this.data[x][y][1]=ImgLue.data[x][y][1];
this.data[x][y][2]=ImgLue.data[x][y][2];
}
}
this.nom=null;
this.ie=new ImageExterneCree(this.data);
((ImageExterneCree)ie).changeImage(this.data); //demande de prendre en compte les changements
return this;
}
} |
la class imageExterneCree
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
public class ImageExterneCree extends ImageExterne{
private int rgbColor(int[] t){
return (255<<24)+(t[0]<<16)+(t[1]<<8)+t[2];
}
public ImageExterneCree(int[][][] tab){
int wid, hei;
wid = tab.length;
hei = tab[0].length;
int[] rgb= new int[wid*hei];
for (int i=0; i<rgb.length; i++){
rgb[i]=rgbColor(tab[i%wid][i/wid]);
}
img = new BufferedImage(wid,hei,BufferedImage.TYPE_INT_RGB);
img.setRGB(0,0,wid,hei,rgb,0,wid);
this.showImage();
}
public void changeImage(int[][][] tab){
int wid, hei;
wid = tab.length;
hei = tab[0].length;
int[] rgb= new int[wid*hei];
for (int i=0; i<rgb.length; i++){
rgb[i]=rgbColor(tab[i%wid][i/wid]);
}
img = new BufferedImage(wid,hei,BufferedImage.TYPE_INT_RGB);
img.setRGB(0,0,wid,hei,rgb,0,wid);
mp.change(img);
}
void sauver(String s) throws IOException{
ImageIO.write(img,"jpeg",new File(s));
}
} |
la class ImageExterneLue
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
public class ImageExterneLue extends ImageExterne{
public ImageExterneLue(String nomf) throws IOException,
FileNotFoundException{
img = ImageIO.read(new File(nomf));
this.showImage();
}
public int[][][] getTableau(){
int wid, hei;
wid = img.getWidth();
hei = img.getHeight();
int[][][] res = new int[wid][hei][3];
int[] rgb = img.getRGB(0,0,wid,hei,null,0,wid);
for (int i=0; i<rgb.length; i++){
res[i%wid][i/wid][0]=rgb[i]>>16 & 0xFF;
res[i%wid][i/wid][1]=rgb[i]>>8 & 0xFF;
res[i%wid][i/wid][2]=rgb[i] & 0xFF;
}
return res;
}
} |