/// <summary> /// jeu qui demande à l'utilisateur de remettre les cases dans le bon ordre /// </summary> /// <param name="fichier">fichier , info de l'image</param> /// <param name="image">l'image définie au début de la classe</param> /// <param name="reponse">ce que renvoie la fonction image découpée</param> public void jouer_puzzle(byte[] fichier, MyImage image, int[] reponse) { byte[] puzzle_tab = new byte[fichier.Length]; byte[,] fichier_mat = Convert_Tab_to_Mat(fichier); byte[,] puzzlefinal = new byte[image.Hauteur, image.Largeur * 3]; int[] tab = new int[6]; int[] reponseJoueur = new int[6]; Console.WriteLine("Voici l'image de Coco mélangée. Vous devez remettre coco dans le bon ordre. Les pièces sont numérotée de la facon suivante"); Console.WriteLine("______"); Console.WriteLine("|4|5|6|"); Console.WriteLine("______"); Console.WriteLine("|1|2|3|"); Console.WriteLine("______"); Console.WriteLine("Quelle case est en bas à gauche ?"); reponseJoueur[0] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Quelle case est en bas au milieu ?"); reponseJoueur[1] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Quelle case est en bas à droite ?"); reponseJoueur[2] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Quelle case est en haut à gauche ?"); reponseJoueur[3] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Quelle case est en haut au milieu ?"); reponseJoueur[4] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Quelle case est en haut à doite ?"); reponseJoueur[5] = Convert.ToInt32(Console.ReadLine()); bool result = true; for (int i = 0; i < 6; i++) { if (reponseJoueur[i] != reponse[i]) { result = false; } } if (result == true) { Console.WriteLine("GAGNE"); } else { Console.WriteLine("Perdu..., les réponses sont : "); for (int i = 0; i < 6; i++) { Console.Write(reponse[i] + ", "); } Console.WriteLine(" " + "\n"); } }
public Jeu(string myfile, MyImage image) { this.image = image; this.myfile = myfile; try { byte[] fichier = File.ReadAllBytes(myfile); string reponse = ""; Console.WriteLine("Que voulez-vous faire ?"); while (true) { // AFFICHAGE DU MENU Console.WriteLine("1- Image en nuance de gris"); Console.WriteLine("2- Image en noir et blanc "); Console.WriteLine("3- Image effet stylé négatif"); Console.WriteLine("4- Image effet miroir vertical"); Console.WriteLine("5- Image effet miroir horizontal"); Console.WriteLine("6- Image rotation 90"); Console.WriteLine("7- Image rotation 180"); Console.WriteLine("8- Image rotation 270"); Console.WriteLine("9- Image agrandie"); Console.WriteLine("10- Image rétrécie"); Console.WriteLine("'sortir' pour arréter"); reponse = Console.ReadLine(); // reponse = reponse de l'utilisateur if (reponse != "") { if (reponse == "1") { byte[] tab = nuanceDeGris(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "2") { byte[] tab = noirEtBlanc(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "3") { byte[] tab = Stylé(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "4") { byte[] tab = effetMiroirVertical(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "5") { byte[] tab = effetMiroirHorizontal(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "6") { byte[] tab = rotation90(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "7") { byte[] tab = rotation180(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "8") { byte[] tab = rotation270(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "9") { byte[] tab = agrandir(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "10") { byte[] tab = Image_Rétrecie(fichier); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez"); Console.WriteLine("////////////////"); } } } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
public Histogramme(string myfile, MyImage image) { this.image = image; this.myfile = myfile; try { byte[] fichier = File.ReadAllBytes(myfile); Console.WriteLine("Quel histogramme voulez vous (général, bleu, rouge, vert) ?"); while (true) { // AFFICHAGE DU MENU Console.WriteLine("1- Général"); Console.WriteLine("2- Bleu"); Console.WriteLine("3- Vert"); Console.WriteLine("4- Rouge"); Console.WriteLine("sortir"); string reponse = Console.ReadLine(); if (reponse != "") { if (reponse == "1") { byte[] histogramme = Histogramme_General(fichier); File.WriteAllBytes("Sortie.bmp", histogramme); Process.Start("Sortie.bmp"); } if (reponse == "2") { int début = 0; byte[] histogramme = Histogramme_Couleur(fichier, début); File.WriteAllBytes("Sortie.bmp", histogramme); Process.Start("Sortie.bmp"); } if (reponse == "3") { int début = 1; byte[] histogramme = Histogramme_Couleur(fichier, début); File.WriteAllBytes("Sortie.bmp", histogramme); Process.Start("Sortie.bmp"); } if (reponse == "4") { int début = 2; byte[] histogramme = Histogramme_Couleur(fichier, début); File.WriteAllBytes("Sortie.bmp", histogramme); Process.Start("Sortie.bmp"); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez"); Console.WriteLine("////////////////"); } } } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { string reponse = ""; string imageChoisie = ""; Console.WriteLine("Que voulez-vous faire ?"); while (true) { Console.WriteLine("1- Avoir des informations sur l'image"); Console.WriteLine("2- Jouer avec l'image"); Console.WriteLine("3- Jouer avec les filtres "); Console.WriteLine("4- Dessiner une fractale"); Console.WriteLine("5- Afficher l'histogramme"); Console.WriteLine("6- Afficher l'image"); Console.WriteLine("7- Image cachée"); Console.WriteLine("8- Jouer au puzzle"); Console.WriteLine("'sortir' pour arréter"); reponse = Console.ReadLine(); // reponse = reponse de l'utilisateur if (reponse != "") { if (reponse == "1") { imageChoisie = Choix_Image(); MyImage InfoImage = new MyImage(imageChoisie); Console.WriteLine(InfoImage.toString()); Console.WriteLine("\n"); } if (reponse == "2") { imageChoisie = Choix_Image(); MyImage InfoImage = new MyImage(imageChoisie); Jeu couleurGris = new Jeu(imageChoisie, InfoImage); } if (reponse == "3") { imageChoisie = Choix_Image(); MyImage InfoImage = new MyImage(imageChoisie); Convolution Mat = new Convolution(imageChoisie, InfoImage); } if (reponse == "4") { Fractale Frac = new Fractale(); } if (reponse == "5") { imageChoisie = Choix_Image(); MyImage InfoImage = new MyImage(imageChoisie); Histogramme Hist = new Histogramme(imageChoisie, InfoImage); } if (reponse == "6") { try { imageChoisie = Choix_Image(); MyImage InfoImage = new MyImage(imageChoisie); byte[] fichier = File.ReadAllBytes(imageChoisie); File.WriteAllBytes("Sortie.bmp", fichier); Process.Start("Sortie.bmp"); } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } } if (reponse == "7") { //Console.WriteLine("Choisir une image pour le fond"); //string imageFond = Choix_Image(); MyImage Fond = new MyImage("test_100_100.bmp"); //Console.WriteLine("Choisir une image pour la cacher"); //string imageCaché = Choix_Image(); MyImage Imagecachée = new MyImage("C.bmp"); Image_Cachée image = new Image_Cachée("test_100_100.bmp", "C.bmp", Imagecachée, Fond); } if (reponse == "8") { imageChoisie = "coco.bmp"; MyImage InfoImage = new MyImage(imageChoisie); Invention_puzzle invention = new Invention_puzzle(imageChoisie, InfoImage); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez !"); Console.WriteLine("////////////////"); } } Console.ReadLine(); }
/// <summary> /// découpe l'image en 6 morceaux et les melange aléatoirement /// </summary> /// <param name="fichier">fichier , info de l'image</param> /// <param name="image">l'image définie au début de la classe</param> /// <param name="r">random, chiffre aléatoire entre 1 et 6</param> /// <returns></returns> public int[] image_decoupee(byte[] fichier, MyImage image, Random r) { byte[] puzzle_tab = new byte[fichier.Length]; byte[,] fichier_mat = Convert_Tab_to_Mat(fichier); byte[,] puzzlefinal = new byte[image.Hauteur, image.Largeur * 3]; int ColonneRang = 0; int LigneRang = 0; int k = 0; int Ipuzzle = 0; int Jpuzzle = 0; int tour = 0; int ligne; int colonne; int[] tab = new int[6]; for (int j = 0; j < 54; j++) { puzzle_tab[j] = fichier[j]; } for (int place = 0; place < 6; place++) { //nombre aléatoire do { k = r.Next(1, 7); }while (k == tab[0] || k == tab[1] || k == tab[2] || k == tab[3] || k == tab[4] || k == tab[5]); { //Console.WriteLine(k); tab[place] = k; if (k == 1) { ColonneRang = 0; LigneRang = 0; } if (k == 2) { ColonneRang = Convert.ToInt32(image.Largeur - 2); LigneRang = 0; } if (k == 3) { ColonneRang = Convert.ToInt32(2 * (image.Largeur) - 1); LigneRang = 0; } if (k == 4) { ColonneRang = 0; LigneRang = Convert.ToInt32((0.5) * image.Hauteur); } if (k == 5) { ColonneRang = Convert.ToInt32((image.Largeur - 2)); LigneRang = Convert.ToInt32((0.5) * image.Hauteur); } if (k == 6) { ColonneRang = Convert.ToInt32(2 * (image.Largeur) - 1); LigneRang = Convert.ToInt32((0.5) * image.Hauteur); } } ligne = LigneRang; for (int i = Ipuzzle; i < Ipuzzle + (0.5) * image.Hauteur - 1; i++) { colonne = ColonneRang; for (int j = Jpuzzle; j < Jpuzzle + image.Largeur - 2; j++) { puzzlefinal[i, j] = fichier_mat[ligne, colonne]; colonne++; } ligne++; colonne = ColonneRang; } tour++; if (tour == 1) { Ipuzzle = 0; Jpuzzle = Convert.ToInt32(image.Largeur - 2); } if (tour == 2) { Ipuzzle = 0; Jpuzzle = Convert.ToInt32(2 * image.Largeur - 1); } if (tour == 3) { Ipuzzle = Convert.ToInt32(0.5 * image.Hauteur); Jpuzzle = 0; } if (tour == 4) { Ipuzzle = Convert.ToInt32(0.5 * image.Hauteur); Jpuzzle = Convert.ToInt32(image.Largeur - 2); } if (tour == 5) { Ipuzzle = Convert.ToInt32(0.5 * image.Hauteur); Jpuzzle = Convert.ToInt32(2 * image.Largeur - 1); } } puzzle_tab = Convert_Mat_to_Tab(puzzlefinal, fichier); File.WriteAllBytes("Sortie.bmp", puzzle_tab); Process.Start("Sortie.bmp"); return(tab); }
public Invention_puzzle(string myfile, MyImage image) { this.image = image; this.myfile = myfile; try { byte[] fichier = File.ReadAllBytes(myfile); string reponse = ""; Console.WriteLine("Que voulez-vous faire ?"); while (true) { // AFFICHAGE DU MENU Console.WriteLine("1- Afficher l'image"); Console.WriteLine("2- Afficher l'image en puzzle "); Console.WriteLine("3- Jouer avec l'image"); Console.WriteLine("'sortir' pour arréter"); reponse = Console.ReadLine(); // reponse = reponse de l'utilisateur if (reponse != "") { if (reponse == "1") { File.WriteAllBytes("Sortie.bmp", fichier); Process.Start("Sortie.bmp"); } if (reponse == "2") { int[] tab = image_decoupee(fichier, image, r); } if (reponse == "3") { jouer_puzzle(fichier, image, image_decoupee(fichier, image, r)); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez"); Console.WriteLine("////////////////"); } } } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
public Convolution(string myfile, MyImage image) { this.image = image; this.myfile = myfile; try { byte[] fichier = File.ReadAllBytes(myfile); //Process.Start(myfile); string reponse = ""; Console.WriteLine("Que voulez-vous faire ?"); while (true) { // AFFICHAGE DU MENU Console.WriteLine("1- Image, flou"); Console.WriteLine("2- Image, renforcement des bords"); Console.WriteLine("3- Image, détection de contour"); Console.WriteLine("4- Image, repoussage"); Console.WriteLine("5- Image, ID"); Console.WriteLine("'sortir' pour arréter"); reponse = Console.ReadLine(); // reponse = reponse de l'utilisateur if (reponse != "") { if (reponse == "1") { int[,] filtre = new int[, ] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }; int diviseur = 9; byte[] tab = Matrice_Convolution(fichier, filtre, diviseur); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "2") { int[,] filtre = new int[, ] { { 0, 0, 0 }, { (-1), 1, 0 }, { 0, 0, 0 } }; int diviseur = 1; byte[] tab = Matrice_Convolution(fichier, filtre, diviseur); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "3") { int[,] filtre = new int[, ] { { 0, 1, 0 }, { 1, -4, 1 }, { 0, 1, 0 } }; int diviseur = 1; byte[] tab = Matrice_Convolution(fichier, filtre, diviseur); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "4") { int[,] filtre = new int[, ] { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; int diviseur = 1; byte[] tab = Matrice_Convolution(fichier, filtre, diviseur); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "5") { int[,] filtre = new int[, ] { { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 } }; int diviseur = 1; byte[] tab = Matrice_Convolution(fichier, filtre, diviseur); File.WriteAllBytes("Sortie.bmp", tab); Process.Start("Sortie.bmp"); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez"); Console.WriteLine("////////////////"); } } } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
public Image_Cachée(string myfile, string myfile2, MyImage file, MyImage file2) { this.file = file; this.file2 = file2; this.myfile = myfile; this.myfile2 = myfile2; try { byte[] cache = File.ReadAllBytes(myfile); byte[] fond = File.ReadAllBytes(myfile2); string reponse = ""; Console.WriteLine("Que voulez-vous faire ?"); while (true) { Console.WriteLine("1- Voir Image"); Console.WriteLine("2- Voir Image 2"); Console.WriteLine("3- Voir avec Image cachée"); Console.WriteLine("4- Retrouver Image 1"); Console.WriteLine("5- Retrouver Image 2"); Console.WriteLine("'sortir' pour arréter"); reponse = Console.ReadLine(); if (reponse != "") { if (reponse == "1") { File.WriteAllBytes("Sortie.bmp", cache); Process.Start("Sortie.bmp"); } if (reponse == "2") { File.WriteAllBytes("Sortie.bmp", fond); Process.Start("Sortie.bmp"); } if (reponse == "3") { byte[] Fichier = Cacher_image(cache, fond); File.WriteAllBytes("Sortie.bmp", Fichier); Process.Start("Sortie.bmp"); } if (reponse == "4") { byte[] Fichier = Cacher_image(cache, fond); byte[] Fond = Retrouver_image_de_fond(Fichier); File.WriteAllBytes("Sortie.bmp", Fond); Process.Start("Sortie.bmp"); } if (reponse == "5") { byte[] Fichier = Cacher_image(cache, fond); byte[] Fond = Retrouver_image_cachée(Fichier); File.WriteAllBytes("Sortie.bmp", Fond); Process.Start("Sortie.bmp"); } if (reponse == "sortir") { Console.WriteLine("Merci et appuyer sur entrée pour arrêter"); break; } } else { Console.WriteLine("////////////////"); Console.WriteLine("erreur sur la réponse, recommencez"); Console.WriteLine("////////////////"); } } } catch (FileNotFoundException e) ///test des exception pour pas que le fichier ne plante { Console.WriteLine(e.Message); } catch (IOException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }