IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Erreur de "ArrayIndexOutOfBoundsException:"


Sujet :

avec Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
        }
    }

  2. #2
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 63
    Par défaut
    il ne te manque pas une virgule a la ligne 28?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Par défaut
    Bonjour,
    Je pense pas, c'est el nom de ma méthode pour incruster. ou alors c'est l'algo de ma méthode qui ne vas pas.
    Merci

  4. #4
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 63
    Par défaut
    Je pensais que ta méthode creerIncrustation prenait 2 paramètres Bitmap et ImgLue et qu'il manquait une virgule entre les deux puisque l'erreur se situe juste apres ligne 30..

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 36
    Par défaut
    Je pense que c'est ma méhode qui ne fonctionne pas, puis qu'il me dit que je sort du tableau.
    Si quelqu'un a une piste pour que je sorte de la, il sera le bien venu

  6. #6
    Membre Expert Avatar de Nico02
    Homme Profil pro
    Developpeur Java/JEE
    Inscrit en
    Février 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Developpeur Java/JEE
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2011
    Messages : 728
    Par défaut
    T'es deux tableaux data et ImgLue font il bien la même taille ?

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo