public void generation(string nom) { switch (this.version) { case (1): Pixel[,] code = new Pixel[21, 21]; //tracage de tous les separateurs for (int i = 0; i < 7; i++) { code[i, 0] = new Pixel((byte)0, (byte)0, (byte)0); code[0, i] = new Pixel((byte)0, (byte)0, (byte)0); code[6, i] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[20 - i, 0] = new Pixel((byte)0, (byte)0, (byte)0); code[20, i] = new Pixel((byte)0, (byte)0, (byte)0); code[14, i] = new Pixel((byte)0, (byte)0, (byte)0); code[20 - i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 20] = new Pixel((byte)0, (byte)0, (byte)0); code[0, 20 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[6, 20 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 14] = new Pixel((byte)0, (byte)0, (byte)0); } for (int i = 0; i < 5; i++) { code[1 + i, 1] = new Pixel((byte)255, (byte)255, (byte)255); code[1, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[5, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 5] = new Pixel((byte)255, (byte)255, (byte)255); code[19 - i, 1] = new Pixel((byte)255, (byte)255, (byte)255); code[19, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[15, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[19 - i, 5] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 19] = new Pixel((byte)255, (byte)255, (byte)255); code[1, 19 - i] = new Pixel((byte)255, (byte)255, (byte)255); code[5, 19 - i] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 15] = new Pixel((byte)255, (byte)255, (byte)255); } for (int i = 0; i < 3; i++) { code[2 + i, 2] = new Pixel((byte)0, (byte)0, (byte)0); code[2, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[4, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 4] = new Pixel((byte)0, (byte)0, (byte)0); code[18 - i, 2] = new Pixel((byte)0, (byte)0, (byte)0); code[18, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[16, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[18 - i, 4] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 18] = new Pixel((byte)0, (byte)0, (byte)0); code[2, 18 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[4, 18 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 16] = new Pixel((byte)0, (byte)0, (byte)0); } code[3, 3] = new Pixel((byte)0, (byte)0, (byte)0); code[17, 3] = new Pixel((byte)0, (byte)0, (byte)0); code[3, 17] = new Pixel((byte)0, (byte)0, (byte)0); //patern de séparation for (int i = 0; i < 8; i++) { code[7, i] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 7] = new Pixel((byte)255, (byte)255, (byte)255); code[13, i] = new Pixel((byte)255, (byte)255, (byte)255); code[20 - i, 7] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 13] = new Pixel((byte)255, (byte)255, (byte)255); code[7, 20 - i] = new Pixel((byte)255, (byte)255, (byte)255); } //motifs de synchronisation for (int i = 8; i < 13; i++) { if (i % 2 == 0) { code[i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[6, i] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[6, i] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 6] = new Pixel((byte)255, (byte)255, (byte)255); } } //implantation du masque for (int i = 0; i < 15; i++) { if (masque[i] == '1') { if (i < 6) { code[8, i] = new Pixel((byte)0, (byte)0, (byte)0); } else if (i < 8) { code[8, 1 + i] = new Pixel((byte)0, (byte)0, (byte)0); } else if (i == 8) { code[7, 8] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[14 - i, 8] = new Pixel((byte)0, (byte)0, (byte)0); }; if (i < 7) { code[20 - i, 8] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[8, 6 + i] = new Pixel((byte)0, (byte)0, (byte)0); } } else { if (i < 6) { code[8, i] = new Pixel((byte)255, (byte)255, (byte)255); } else if (i < 8) { code[8, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); } else if (i == 8) { code[7, 8] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[14 - i, 8] = new Pixel((byte)255, (byte)255, (byte)255); }; if (i < 7) { code[20 - i, 8] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[8, 6 + i] = new Pixel((byte)255, (byte)255, (byte)255); } } } //dark module code[13, 8] = new Pixel((byte)0, (byte)0, (byte)0); //ecriture du code bool montee = true; int index = 0; for (int x = 20; x > 0; x -= 2) { if (x == 6) { x--; } if (montee) { for (int y = 20; y >= 0; y--) { if (code[y, x] == null) { if (data[index] == (byte)0) { code[y, x] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } if (code[y, x - 1] == null) { if (data[index] == (byte)0) { code[y, x - 1] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x - 1] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } } montee = false; } else { for (int y = 0; y < 21; y++) { if (code[y, x] == null) { if (data[index] == (byte)0) { code[y, x] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } if (code[y, x - 1] == null) { if (data[index] == (byte)0) { code[y, x - 1] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x - 1] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } } montee = true; } } MyImage QR = new MyImage(21, code); QR.Agrandissement(4); QR.Miroir('V'); QR.From_Image_To_File(nom); break; case (2): code = new Pixel[25, 25]; //tracage de tous les separateurs for (int i = 0; i < 7; i++) { code[i, 0] = new Pixel((byte)0, (byte)0, (byte)0); code[0, i] = new Pixel((byte)0, (byte)0, (byte)0); code[6, i] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[24 - i, 0] = new Pixel((byte)0, (byte)0, (byte)0); code[24, i] = new Pixel((byte)0, (byte)0, (byte)0); code[18, i] = new Pixel((byte)0, (byte)0, (byte)0); code[24 - i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 24] = new Pixel((byte)0, (byte)0, (byte)0); code[0, 24 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[6, 24 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[i, 18] = new Pixel((byte)0, (byte)0, (byte)0); } for (int i = 0; i < 5; i++) { code[1 + i, 1] = new Pixel((byte)255, (byte)255, (byte)255); code[1, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[5, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 5] = new Pixel((byte)255, (byte)255, (byte)255); code[23 - i, 1] = new Pixel((byte)255, (byte)255, (byte)255); code[23, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[19, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[23 - i, 5] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 23] = new Pixel((byte)255, (byte)255, (byte)255); code[1, 23 - i] = new Pixel((byte)255, (byte)255, (byte)255); code[5, 23 - i] = new Pixel((byte)255, (byte)255, (byte)255); code[1 + i, 19] = new Pixel((byte)255, (byte)255, (byte)255); } for (int i = 0; i < 3; i++) { code[2 + i, 2] = new Pixel((byte)0, (byte)0, (byte)0); code[2, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[4, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 4] = new Pixel((byte)0, (byte)0, (byte)0); code[22 - i, 2] = new Pixel((byte)0, (byte)0, (byte)0); code[22, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[20, 2 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[22 - i, 4] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 22] = new Pixel((byte)0, (byte)0, (byte)0); code[2, 22 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[4, 22 - i] = new Pixel((byte)0, (byte)0, (byte)0); code[2 + i, 20] = new Pixel((byte)0, (byte)0, (byte)0); } code[3, 3] = new Pixel((byte)0, (byte)0, (byte)0); code[21, 3] = new Pixel((byte)0, (byte)0, (byte)0); code[3, 21] = new Pixel((byte)0, (byte)0, (byte)0); //patern de séparation for (int i = 0; i < 8; i++) { code[7, i] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 7] = new Pixel((byte)255, (byte)255, (byte)255); code[17, i] = new Pixel((byte)255, (byte)255, (byte)255); code[24 - i, 7] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 13] = new Pixel((byte)255, (byte)255, (byte)255); code[7, 24 - i] = new Pixel((byte)255, (byte)255, (byte)255); } //motifs de synchronisation for (int i = 8; i < 17; i++) { if (i % 2 == 0) { code[i, 6] = new Pixel((byte)0, (byte)0, (byte)0); code[6, i] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[6, i] = new Pixel((byte)255, (byte)255, (byte)255); code[i, 6] = new Pixel((byte)255, (byte)255, (byte)255); } } //implantation du masque for (int i = 0; i < 15; i++) { if (masque[i] == '1') { if (i < 6) { code[8, i] = new Pixel((byte)0, (byte)0, (byte)0); } else if (i < 8) { code[8, 1 + i] = new Pixel((byte)0, (byte)0, (byte)0); } else if (i == 8) { code[7, 8] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[14 - i, 8] = new Pixel((byte)0, (byte)0, (byte)0); } if (i < 7) { code[24 - i, 8] = new Pixel((byte)0, (byte)0, (byte)0); } else { code[8, 10 + i] = new Pixel((byte)0, (byte)0, (byte)0); } } else { if (i < 6) { code[8, i] = new Pixel((byte)255, (byte)255, (byte)255); } else if (i < 8) { code[8, 1 + i] = new Pixel((byte)255, (byte)255, (byte)255); } else if (i == 8) { code[7, 8] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[14 - i, 8] = new Pixel((byte)255, (byte)255, (byte)255); } if (i < 7) { code[24 - i, 8] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[8, 10 + i] = new Pixel((byte)255, (byte)255, (byte)255); } } } //dark module code[8, 13] = new Pixel((byte)0, (byte)0, (byte)0); // module d'alignement for (int i = 0; i < 5; i++) { code[16 + i, 16] = new Pixel((byte)0, (byte)0, (byte)0); code[16, 16 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[20, 16 + i] = new Pixel((byte)0, (byte)0, (byte)0); code[16 + i, 20] = new Pixel((byte)0, (byte)0, (byte)0); } for (int i = 0; i < 3; i++) { code[17 + i, 17] = new Pixel((byte)255, (byte)255, (byte)255); code[17, 17 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[19, 17 + i] = new Pixel((byte)255, (byte)255, (byte)255); code[17 + i, 19] = new Pixel((byte)255, (byte)255, (byte)255); } code[18, 18] = new Pixel((byte)0, (byte)0, (byte)0); //ecriture du code montee = true; index = 0; for (int x = 24; x > 0; x -= 2) { if (x == 6) { x--; } if (montee) { for (int y = 24; y >= 0; y--) { if (code[y, x] == null) { if (data[index] == (byte)0) { code[y, x] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } if (code[y, x - 1] == null) { if (data[index] == (byte)0) { code[y, x - 1] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x - 1] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } } montee = false; } else { for (int y = 0; y < 25; y++) { if (code[y, x] == null) { if (data[index] == (byte)0) { code[y, x] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } if (code[y, x - 1] == null) { if (data[index] == (byte)0) { code[y, x - 1] = new Pixel((byte)255, (byte)255, (byte)255); } else { code[y, x - 1] = new Pixel((byte)0, (byte)0, (byte)0); } index++; } } montee = true; } } QR = new MyImage(25, code); QR.Agrandissement(4); QR.Miroir('V'); QR.From_Image_To_File(nom); break; } }
//Méthode permettant de décoder une image dans une autre image public void Décodage() { char[] Rbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Vbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Bbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Rbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Vbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Bbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; Pixel[,] im2 = new Pixel[haut, large]; for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { im2[i, j] = new Pixel(0, 0, 0); } } for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { string rouge = Convert.ToString(image[i, j].Red, 2); string bleu = Convert.ToString(image[i, j].Blue, 2); string vert = Convert.ToString(image[i, j].Green, 2); int compteur = 0; for (int u = rouge.Length - 1; u >= 0; u--) { Rbis[7 - compteur] = Convert.ToChar(rouge[u]); compteur++; } compteur = 0; for (int u = vert.Length - 1; u >= 0; u--) { Vbis[7 - compteur] = Convert.ToChar(vert[u]); compteur++; } compteur = 0; for (int u = bleu.Length - 1; u >= 0; u--) { Bbis[7 - compteur] = Convert.ToChar(bleu[u]); compteur++; } for (int y = 0; y < 4; y++) { Rbis2[y] = Rbis[y + 4]; Bbis2[y] = Bbis[y + 4]; Vbis2[y] = Vbis[y + 4]; } string Rouge = new string(Rbis2); string Vert = new string(Vbis2); string Bleu = new string(Bbis2); im2[i, j].Red = (byte)Convert.ToInt32(Rouge, 2); im2[i, j].Green = (byte)Convert.ToInt32(Vert, 2); im2[i, j].Blue = (byte)Convert.ToInt32(Bleu, 2); } } image = im2; }
//Méthode permettant de coder une image dans une autre image public void ImageDansImage(string fichier1) { byte[] file2 = File.ReadAllBytes(fichier1); int l = large; int h = haut; int compt = 0; Pixel[,] im2 = new Pixel[h, l]; for (int i = 0; i < h; i++) { for (int j = 0; j < l; j++) { im2[i, j] = new Pixel(0, 0, 0); im2[i, j].Red = file2[54 + compt]; im2[i, j].Green = file2[54 + 1 + compt]; im2[i, j].Blue = file2[54 + 2 + compt]; compt = compt + 3; } } int hbis = h; int lbis = l; Pixel[,] ImageFinale = new Pixel[haut, large]; for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { ImageFinale[i, j] = image[i, j]; } } for (int i = 0; i < hbis; i++) { for (int j = 0; j < lbis; j++) { string R = Convert.ToString(image[i, j].Red, 2); string B = Convert.ToString(image[i, j].Blue, 2); string V = Convert.ToString(image[i, j].Green, 2); string R2 = Convert.ToString(im2[i, j].Red, 2); string B2 = Convert.ToString(im2[i, j].Blue, 2); string V2 = Convert.ToString(im2[i, j].Green, 2); char[] Rbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Vbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Bbis = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Rbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Vbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Bbis2 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Rbis3 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Vbis3 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; char[] Bbis3 = new char[8] { '0', '0', '0', '0', '0', '0', '0', '0' }; int compteur = 0; for (int u = R.Length - 1; u >= 0; u--) { Rbis[7 - compteur] = Convert.ToChar(R[u]); compteur++; } compteur = 0; for (int u = V.Length - 1; u >= 0; u--) { Vbis[7 - compteur] = Convert.ToChar(V[u]); compteur++; } compteur = 0; for (int u = B.Length - 1; u >= 0; u--) { Bbis[7 - compteur] = Convert.ToChar(B[u]); compteur++; } compteur = 0; for (int u = R2.Length - 1; u >= 0; u--) { Rbis2[7 - compteur] = Convert.ToChar(R2[u]); compteur++; } compteur = 0; for (int u = V2.Length - 1; u >= 0; u--) { Vbis2[7 - compteur] = Convert.ToChar(V2[u]); compteur++; } compteur = 0; for (int u = B2.Length - 1; u >= 0; u--) { Bbis2[7 - compteur] = Convert.ToChar(B2[u]); compteur++; } for (int y = 0; y < 4; y++) { Rbis3[y] = Rbis[y]; Vbis3[y] = Vbis[y]; Bbis3[y] = Bbis[y]; Rbis3[4 + y] = Rbis2[y]; Vbis3[4 + y] = Vbis2[y]; Bbis3[4 + y] = Bbis2[y]; } string Rouge = new string(Rbis3); string Vert = new string(Vbis3); string Bleu = new string(Bbis3); ImageFinale[i, j].Red = (byte)Convert.ToInt32(Rouge, 2); ImageFinale[i, j].Green = (byte)Convert.ToInt32(Vert, 2); ImageFinale[i, j].Blue = (byte)Convert.ToInt32(Bleu, 2); } } image = ImageFinale; }
//Méthode qui permet de réaliser l'histogramme des couleurs d'une image public void Histogramme() { int taille2 = image.GetLength(0) * image.GetLength(1); int[] R = new int[256]; int[] V = new int[256]; int[] B = new int[256]; byte val1 = 0; byte val2 = 0; byte val3 = 0; for (int k = 0; k < 256; k++) { R[k] = 0; V[k] = 0; B[k] = 0; } for (int i = 0; i < image.GetLength(0); i++) { for (int j = 0; j < image.GetLength(1); j++) { val1 = image[i, j].Red; val2 = image[i, j].Green; val3 = image[i, j].Blue; R[val1] += 1; V[val2] += 1; B[val3] += 1; } } haut = 1000; for (int l = 0; l < 256; l++) { if (R[l] >= haut) { haut = R[l]; } if (V[l] >= haut) { haut = V[l]; } if (B[l] >= haut) { haut = B[l]; } } large = 788; Pixel[,] hist = new Pixel[haut, large]; for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { hist[i, j] = new Pixel(0, 0, 0); } } for (int a = 0; a < haut; a++) { for (int b = 0; b < large; b++) { hist[a, b].Red = 255; hist[a, b].Blue = 255; hist[a, b].Green = 255; } } for (int m = 0; m < 255; m++) { for (int n = 0; n < R[m]; n++) { hist[haut - n - 1, m] = new Pixel(0, 0, 0); hist[haut - n - 1, m].Red = 255; hist[haut - n - 1, m].Blue = 0; hist[haut - n - 1, m].Green = 0; } } for (int m = 266; m < 521; m++) { for (int n = 0; n < B[m - 266]; n++) { hist[haut - n - 1, m] = new Pixel(0, 0, 0); hist[haut - n - 1, m].Red = 0; hist[haut - n - 1, m].Blue = 255; hist[haut - n - 1, m].Green = 0; } } for (int m = 532; m < 788; m++) { for (int n = 0; n < V[m - 532]; n++) { hist[haut - n - 1, m] = new Pixel(0, 0, 0); hist[haut - n - 1, m].Red = 0; hist[haut - n - 1, m].Blue = 0; hist[haut - n - 1, m].Green = 255; } } Pixel[,] Histogramme = new Pixel[haut, large]; for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { Histogramme[i, j] = new Pixel(0, 0, 0); } } for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { Histogramme[i, j].Red = 255; Histogramme[i, j].Blue = 255; Histogramme[i, j].Green = 255; } } for (int i = 0; i < haut; i++) { for (int j = 0; j < large; j++) { Histogramme[haut - i - 1, j] = hist[i, j]; } } image = Histogramme; haut = 1000; large = 788; taille = haut * large * 3 + 54; byte[] temp = Convertir_Int_To_Endian(large, 4); for (int i = 0; i < 4; i++) { header[18 + i] = temp[i]; } temp = Convertir_Int_To_Endian(haut, 4); for (int i = 0; i < 4; i++) { header[22 + i] = temp[i]; } temp = Convertir_Int_To_Endian(taille, 4); for (int i = 0; i < 4; i++) { header[2 + i] = temp[i]; } }
//Méthode qui permet de faire la matrice de convolution et qui est réutilisée dans la méthode Convolution private Pixel Operation(int[,] matrice, int i, int j) { byte r; byte g; byte b; if (i == 0) { if (j == 0) { r = (byte)((image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 4); g = (byte)((image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 4); b = (byte)((image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 4); } else if (j == haut - 1) { r = (byte)((image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2]) / 4); g = (byte)((image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2]) / 4); b = (byte)((image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2]) / 4); } else { r = (byte)((image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 6); g = (byte)((image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 6); b = (byte)((image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 6); } } else if (i == large - 1) { if (j == 0) { r = (byte)((image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1]) / 4); g = (byte)((image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1]) / 4); b = (byte)((image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1]) / 4); } else if (j == haut - 1) { r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1]) / 4); g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1]) / 4); b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1]) / 4); } else { r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1]) / 6); g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1]) / 6); b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1]) / 6); } } else if (j == 0) { r = (byte)((image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 6); g = (byte)((image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 6); b = (byte)((image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 6); } else if (j == haut - 1) { r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2]) / 6); g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2]) / 6); b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2]) / 6); } else { r = (byte)((image[j - 1, i - 1].Red * matrice[0, 0] + image[j - 1, i].Red * matrice[0, 1] + image[j - 1, i + 1].Red * matrice[0, 2] + image[j, i - 1].Red * matrice[1, 0] + image[j, i].Red * matrice[1, 1] + image[j, i + 1].Red * matrice[1, 2] + image[j + 1, i - 1].Red * matrice[2, 0] + image[j + 1, i].Red * matrice[2, 1] + image[j + 1, i + 1].Red * matrice[2, 2]) / 9); g = (byte)((image[j - 1, i - 1].Green * matrice[0, 0] + image[j - 1, i].Green * matrice[0, 1] + image[j - 1, i + 1].Green * matrice[0, 2] + image[j, i - 1].Green * matrice[1, 0] + image[j, i].Green * matrice[1, 1] + image[j, i + 1].Green * matrice[1, 2] + image[j + 1, i - 1].Green * matrice[2, 0] + image[j + 1, i].Green * matrice[2, 1] + image[j + 1, i + 1].Green * matrice[2, 2]) / 9); b = (byte)((image[j - 1, i - 1].Blue * matrice[0, 0] + image[j - 1, i].Blue * matrice[0, 1] + image[j - 1, i + 1].Blue * matrice[0, 2] + image[j, i - 1].Blue * matrice[1, 0] + image[j, i].Blue * matrice[1, 1] + image[j, i + 1].Blue * matrice[1, 2] + image[j + 1, i - 1].Blue * matrice[2, 0] + image[j + 1, i].Blue * matrice[2, 1] + image[j + 1, i + 1].Blue * matrice[2, 2]) / 9); } Pixel res = new Pixel(r, g, b); return(res); }
//Méthode qui permet de tourner une image selon n'importe quel angle public void Rotation(int angleint) { int taille1 = Convert.ToInt32(Math.Sqrt(haut * haut + large * large)) + 1; Pixel[,] image1 = new Pixel[taille1, taille1]; Pixel[,] imageTemp = new Pixel[taille1, taille1]; int X = (taille1 - haut) / 2; int Y = (taille1 - large) / 2; double angle = (angleint * Math.PI) / 180; for (int k = 0; k < taille1; k++) { for (int l = 0; l < taille1; l++) { image1[l, k] = new Pixel((byte)0, (byte)0, (byte)0); if (l >= X && l < X + haut && k >= Y && k < Y + large) { imageTemp[l, k] = image[l - X, k - Y]; } else { imageTemp[l, k] = new Pixel((byte)0, (byte)0, (byte)0); } } } image = imageTemp; X = taille1 / 2; Y = taille1 / 2; for (int j = 0; j < taille1; j++) { for (int i = 0; i < taille1; i++) { int tempi = Convert.ToInt32((i - X) * Math.Cos(angle) - (j - Y) * Math.Sin(angle) + X); int tempj = Convert.ToInt32((i - X) * Math.Sin(angle) + (j - Y) * Math.Cos(angle) + Y); if (tempj < taille1 && tempi < taille1 && 0 <= tempj && 0 <= tempi) { image1[tempj, tempi] = image[j, i]; } } } image = image1; haut = taille1; large = taille1; taille = haut * large * 3 + 54; byte[] temp = Convertir_Int_To_Endian(large, 4); for (int i = 0; i < 4; i++) { header[18 + i] = temp[i]; } temp = Convertir_Int_To_Endian(haut, 4); for (int i = 0; i < 4; i++) { header[22 + i] = temp[i]; } temp = Convertir_Int_To_Endian(taille, 4); for (int i = 0; i < 4; i++) { header[2 + i] = temp[i]; } Agrandissement(4); }