edbarbier
Messages postés7Date d'inscriptionjeudi 12 novembre 2009StatutMembreDernière intervention18 novembre 2009
-
12 nov. 2009 à 22:50
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023
-
17 nov. 2009 à 15:11
suis débutant. Le programme compile mais ne me renvoi rien.
En faisant divers tests, j'ai eu parfois des erreurs de compilation du genre variable pas initialisées, ou bien le programme me renvoyait des valeurs bizares. Bref j'ai besoin d'un petit coup de main.
import java.lang.*;
import tp3.*;
class tp3
{
public static int [][] getImageData(String path)
{
int y = 0; // COLONNES
int x = 0; // LIGNES
int [][] tab = new int [0][0];
path = new String ("C:\\Users\\Utilisateur\\Desktop\\UCL\\ECGE12BA\\sinf1160\\test.jpg");
for(x = 0; x < tab.length;x++)
{
for(y = 0; y < tab[x].length; y++)
{
System.out.println(tab[y]+","+tab[x]);
}
}
return tab;
}
public static void main(String [] args)
{
int [][] tab;
int x;
int y;
String path = ("C:\\Users\\Utilisateur\\Desktop\\UCL\\ECGE12BA\\sinf1160\\test.jpg");
tab= getImageData(path);
System.out.println("Voici l'image mise sous forme de tableau");
}
}
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 12 nov. 2009 à 23:06
Salut,
Tu es encore très loin du résultat que tu cherches à obtenir : ton code ne fait rien du tout actuellement : il ne fait que créer un tableau de taille 0 et une chaîne de caractère codée en dur...
Il te faut ouvrir le fichier, récupèrer la matrice de pixel, calculer la taille, créer ton tableau en conséquence, extraire les pixels un à un afin de calcul le niveau de gris correspondant, bref, il te reste encore beaucoup de boulot !
Déjà, pour corriger un minimum ton code :
import java.lang.*;
import tp3.*;
class tp3
{
public static int [][] getImageData(String path)
{
int y = 0; // COLONNES
int x = 0; // LIGNES
int nombreLigne = 10; // à calculer bien entendu !
int nombreColonne = 10; // à calculer bien entendu !
int [][] tab = new int [nombreLigne][nombreColonne];
File fichier = new File(path);
for(x = 0; x < tab.length;x++)
{
for(y = 0; y < tab[x].length; y++)
{
// System.out.println(tab[y]+","+tab[x]); TU N'OBTIENDRAS RIEN AVEC CETTE LIGNE TANT QUE TON TABLEAU NE SERA PAS REMPLIT...
}
}
return tab;
}
public static void main(String [] args)
{
int [][] tab;
int x;
int y;
String path = ("C:\\Users\\Utilisateur\\Desktop\\UCL\\ECGE12BA\\sinf1160\\test.jpg");
tab= getImageData(path);
System.out.println("Voici l'image mise sous forme de tableau");
}
}
______________________________________
DarK Sidious