Exemplo n.º 1
0
 public byte[] RemplissageHEADERNouvelleImageBmp()
 {
     CPixels[,] matricePxl = new CPixels[m_hauteurFichierInt, m_largeurFichierInt];
     // Le HEADER des bmp fait 54 octets (entre l'index 0 et l'index 53), il faut donc le construire "à la main" à l'aide des variables crées ci-dessus et de ce lien : http://www.commentcamarche.net/contents/1200-bmp-format-bmp
     // Initialisation du tableau d'octet
     byte[] tableauImageAAfficherByte = new byte[(matricePxl.GetLength(0) * matricePxl.GetLength(1) * 3) + m_tailleOffSetInt];
     // Remplissage du tableau d'octet pour les 54 premiers octets composants le HEADER
     tableauImageAAfficherByte[0] = 66; //par définition d'un fichier bmp
     tableauImageAAfficherByte[1] = 77; //par définition d'un fichier bmp
     for (int i = 2; i < 6; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleFicherByte[i - 2];
     }
     for (int i = 6; i < 10; i++)
     {
         tableauImageAAfficherByte[i] = 0; // par définition champs réservé voir site internet
     }
     for (int i = 10; i < 14; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleOffSetByte[i - 10];
     }
     byte[] tailleEnteteByte = { 40, 0, 0, 0 }; // fixé pour les fichiers traités
     for (int i = 14; i < 18; i++)
     {
         tableauImageAAfficherByte[i] = tailleEnteteByte[i - 14];
     }
     for (int i = 18; i < 22; i++)
     {
         tableauImageAAfficherByte[i] = m_largeurImageByte[i - 18];
     }
     for (int i = 22; i < 26; i++)
     {
         tableauImageAAfficherByte[i] = m_hauteurImageByte[i - 22];
     }
     tableauImageAAfficherByte[26] = 1;                           // par définition pour les fichiers bmp
     tableauImageAAfficherByte[27] = 0;                           // par définition pour les fichiers bmp
     tableauImageAAfficherByte[28] = m_nombreOctetParCouleurByte; // pour les fichiers que l'on traite c'est toujours 24 bits
     tableauImageAAfficherByte[29] = 0;                           // car l'octet 28 et 29 définissent le nombre de couleur par octet, or cette info est codée en 2 bits
     for (int i = 30; i < 34; i++)
     {
         tableauImageAAfficherByte[i] = 0; // octets pour la compression, ici elle est nulle
     }
     for (int i = 34; i < 38; i++)
     {
         tableauImageAAfficherByte[i] = m_tailleImageByte[i - 34];
     }
     for (int i = 38; i < m_tailleOffSetInt; i++)
     {
         tableauImageAAfficherByte[i] = 0; // défini à 0 cf le lien internet
     }
     //for(int i =0; i < tableauImageAAfficherByte.Length; i++)
     //{
     //    Console.WriteLine("¨Pour i = " + i + " l'octet est égale à :" + tableauImageAAfficherByte[i]);
     //}
     return(tableauImageAAfficherByte);
 }
Exemplo n.º 2
0
        public CPixels[,] Rotation90SensTrigoPxl()
        {
            // On ne s'occupe pas de savoir si l'image est rectangle ou carré,
            // Si l'algo traite les rectangles il traitera les carrés.
            CPixels[,] matriceRGB_Returned = new CPixels[m_matriceRGB.GetLength(1), m_matriceRGB.GetLength(0)];
            //AffichageMatriceRGB();
            for (int i = 0; i < matriceRGB_Returned.GetLength(0); i++)
            {
                for (int j = 0; j < matriceRGB_Returned.GetLength(1); j++)
                {
                    //Console.WriteLine("Valeur matriceRGB en (" + i + "," + j + ") : " + m_matriceRGB[i,j].DisplayPixelStr());
                    matriceRGB_Returned[i, j] = m_matriceRGB[m_matriceRGB.GetLength(0) - 1 - j, i];
                    //Console.WriteLine("Valeur nouvelle Matrice en (" + indexI + "," + indexJ + ") : " + resultRotateMatrixRGB[indexI, indexJ].DisplayPixelStr());
                }
            }
            // A partir de la, on a notre nouvelle matrice résultant de m_matriceRGB,

            return(matriceRGB_Returned);
        }
Exemplo n.º 3
0
        public CPixels[,] FiltreEstampage_Pxl()
        {
            CPixels[,] matriceRGB_Returned = new CPixels[m_matriceRGB.GetLength(0), m_matriceRGB.GetLength(1)];
            // On s'appuie sur le site : http://tavmjong.free.fr/INKSCAPE/MANUAL/html_fr/Filters-Pixel.html

            // La matrice permettant de faire l'estampage est [{-2,0,0};{0,1,0};{0,0,2}]

            // Pour ce filtre, il suffit à partir du pixel initial situé en [i,j] de prendre,
            // Le pixel en [i-1,j-1] et en [i+1,j+1]
            // Donc en [0,0] et en [Get(0),Get(1)] ce calcul sera impossible et égal à 0
            try
            {
                int resultatPixelRougeInt     = Int32.MinValue;
                int pixelRougeEnHautGaucheInt = Int32.MinValue; // car va contenir une valeur négative
                int resultatPixelVertInt      = Int32.MinValue;
                int pixelVertEnHautGaucheInt  = Int32.MinValue; // car va contenir une valeur négative
                int resultatPixelBleuInt      = Int32.MinValue;
                int pixelBleuEnHautGaucheInt  = Int32.MinValue; // car va contenir une valeur négative
                for (int i = 0; i < matriceRGB_Returned.GetLength(0); i++)
                {
                    for (int j = 0; j < matriceRGB_Returned.GetLength(1); j++)
                    {
                        //Pour les frontières on les initialise à 0

                        if (i == 0)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe i=0 en [" + i + "," + j + "]");
                        }
                        else if (j == 0)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe j = 0 en [" + i + "," + j + "]");
                        }
                        else if (i == matriceRGB_Returned.GetLength(0) - 1)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe i = Get(0) en [" + i + "," + j + "]");
                        }
                        else if (j == matriceRGB_Returned.GetLength(1) - 1)
                        {
                            matriceRGB_Returned[i, j] = new CPixels();
                            //Console.WriteLine("Je passe j = Get(1) en [" + i + "," + j + "]");
                        }
                        else
                        {
                            //Pour le pixel Bleu
                            pixelBleuEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelBleuByte * (-2);
                            resultatPixelBleuInt     = (pixelBleuEnHautGaucheInt + m_matriceRGB[i, j].PixelBleuByte + m_matriceRGB[i + 1, j + 1].PixelBleuByte * 2) / 3; //stockage dans le pixel initial

                            //Pour le pixel Vert
                            pixelVertEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelVertByte * (-2);
                            resultatPixelVertInt     = (pixelVertEnHautGaucheInt + m_matriceRGB[i, j].PixelVertByte + m_matriceRGB[i + 1, j + 1].PixelVertByte * 2) / 3; //stockage dans le pixel initial

                            //Pour le pixel Rouge
                            pixelRougeEnHautGaucheInt = m_matriceRGB[i - 1, j - 1].PixelRougeByte * (-2);
                            resultatPixelRougeInt     = (pixelRougeEnHautGaucheInt + m_matriceRGB[i, j].PixelRougeByte + m_matriceRGB[i + 1, j + 1].PixelRougeByte * 2) / 3; //stockage dans le pixel initial

                            // Construction de la nouvelle matrice en lui applicant le nouveau pixel
                            //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                            //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                            //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                            if (resultatPixelBleuInt < 0)
                            {
                                resultatPixelBleuInt = -1 * resultatPixelBleuInt;
                            }
                            if (resultatPixelVertInt < 0)
                            {
                                resultatPixelVertInt = -1 * resultatPixelVertInt;
                            }
                            if (resultatPixelRougeInt < 0)
                            {
                                resultatPixelRougeInt = -1 * resultatPixelRougeInt;
                            }
                            //Console.WriteLine("Pixel bleu : " + resultatPixelBleuInt);
                            //Console.WriteLine("Pixel vert : " + resultatPixelVertInt);
                            //Console.WriteLine("Pixel rouge : " + resultatPixelRougeInt);
                            matriceRGB_Returned[i, j] = new CPixels(Convertir_Int_To_Byte(resultatPixelBleuInt), Convertir_Int_To_Byte(resultatPixelVertInt), Convertir_Int_To_Byte(resultatPixelRougeInt));
                        }
                        //Console.ReadKey();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERREUR dans méthode FiltreEstampage_Pxl()");
                Console.WriteLine(e.Message);
            }
            return(matriceRGB_Returned);
        }
Exemplo n.º 4
0
        public static CPixels[,] RemplissageMatriceInitial_M()
        {
            CPixels[,] m_matriceInitialPrenom = new CPixels[240, 240]; // TAILLE Image a choisir, attention largeur doit etre un multiple de 4
            //On parcourt la matrice colonne par colonne
            //On forme un premier rectangle
            for (int j = 0; j < (m_matriceInitialPrenom.GetLength(1) / 5); j++)
            {
                for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
            }
            // On forme la première diagonale descendante de la lettre M
            int decalageInt = 0;

            for (int j = (m_matriceInitialPrenom.GetLength(1) / 5); j < (m_matriceInitialPrenom.GetLength(1) / 2); j++)
            {
                for (int i = 0; i <= decalageInt; i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                decalageInt++;
                for (int i = decalageInt; i < (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
                for (int i = (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                // ICI on parcouru toute une colonne de la matrice
            }
            //ICI on va s'attaquer maintenant à la diagonale montante de la lettre M
            #region 1er jet
            for (int j = (m_matriceInitialPrenom.GetLength(1) / 2); j < (m_matriceInitialPrenom.GetLength(1) - (m_matriceInitialPrenom.GetLength(1) / 5)); j++)
            {
                if (decalageInt != 0)
                {
                    decalageInt--;
                }
                for (int i = 0; i < decalageInt; i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                for (int i = decalageInt; i < (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
                for (int i = (decalageInt + (m_matriceInitialPrenom.GetLength(1) / 4)); i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 0, 0);
                }
                #endregion
                //ICI on a parcouru toute une colonne de la matrice
            }
            //ICI on a fini la diagonale montante, on s'attaque au dernier rectangle de la lettre M
            for (int j = (m_matriceInitialPrenom.GetLength(1) - (m_matriceInitialPrenom.GetLength(1) / 5)); j < m_matriceInitialPrenom.GetLength(1); j++)
            {
                for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
                {
                    m_matriceInitialPrenom[i, j] = new CPixels(0, 255, 0);
                }
            } // On a terminé de parcourir toute notre matrice (image)

            CPixels memoire = new CPixels();
            for (int i = 0; i < m_matriceInitialPrenom.GetLength(0); i++)
            {
                for (int j = 0; j < m_matriceInitialPrenom.GetLength(1); j++)
                {
                    memoire = m_matriceInitialPrenom[i, j];
                    m_matriceInitialPrenom[i, j] = m_matriceInitialPrenom[(m_matriceInitialPrenom.GetLength(0) - 1 - i), j];
                    m_matriceInitialPrenom[(m_matriceInitialPrenom.GetLength(0) - 1 - i), j] = memoire;
                }
            }
            //AfficherMatricePxl(m_matriceInitialPrenom);
            m_matriceInitialPrenom = tourner180Pxl(m_matriceInitialPrenom); // lecture en little endian, besoin de renverser la matrice pour que la lecture se fasse dans le bon sens
            //Console.WriteLine();
            //AfficherMatricePxl(m_matriceInitialPrenom);
            return(m_matriceInitialPrenom);
        }