예제 #1
0
        //Constructeurs
        public MyImage(string myfile)
        {
            //Création d'un tableau qui contient toute l'image
            byte[] Myfile = File.ReadAllBytes(myfile);
            //Récupération du type d'image et conversion de l'ascii en string
            TypeImage = "";
            for (int i = 0; i < 2; i++)
            {
                char temp = (char)myfile[i];
                TypeImage += temp;
            }
            //Pour taillefichier,hauteur,largeur et NbrBits : création d'un tableau de byte de la bonne taille et récupération des valeurs dans le grand tableau.
            //A convertir avec Convertir_Endian_To_Int pour obtenir les nombres
            TailleFichier = new byte[4];
            for (int i = 2; i < 6; i++)
            {
                TailleFichier[i - 2] = Myfile[i];
            }
            Offset = new byte[4];
            for (int i = 10; i < 14; i++)
            {
                Offset[i - 10] = Myfile[i];
            }
            Largeur = new byte[4];
            for (int i = 18; i < 22; i++)
            {
                Largeur[i - 18] = Myfile[i];
            }
            Hauteur = new byte[4];
            for (int i = 22; i < 26; i++)
            {
                Hauteur[i - 22] = Myfile[i];
            }
            NbrBits = new byte[2];
            for (int i = 28; i < 30; i++)
            {
                NbrBits[i - 28] = Myfile[i];
            }
            int LargeurInt = Convertir_Endian_To_Int(Largeur);
            int HauteurInt = Convertir_Endian_To_Int(Hauteur);

            image = new Pixel[HauteurInt, LargeurInt];

            Pixel[] tabIntermédiaire = new Pixel[myfile.Length - 54];

            int j = 0;

            for (int i = 54; i < myfile.Length; i += 3)
            {
                int Red   = myfile[i];
                int Green = myfile[i + 1];
                int Blue  = myfile[i + 2];
                tabIntermédiaire[j] = new Pixel(Red, Green, Blue);
                j++;
            }
            j = 0;
            int ligne = 0;

            while (ligne < HauteurInt)
            {
                for (int colonne = 0; colonne < LargeurInt; colonne++)
                {
                    image[ligne, colonne] = tabIntermédiaire[j];
                    j++;
                }
                ligne++;
            }
        }