Esempio n. 1
0
        public static void BMPToBinary(string pathToFolder, string pathToWrite)
        {
            Console.WriteLine("Converting BMP files to Binary file(CVID)..");
            IFormatter formatter = new BinaryFormatter();

            string[]        files      = Directory.GetFiles(pathToFolder);
            List <Coords>[] data       = new List <Coords> [files.Length];
            FileStream      fileStream = new FileStream(pathToWrite, FileMode.Create);

            for (int i = 0; i < files.Length; i++)
            {
                Bitmap bitmap = (Bitmap)Image.FromFile(files[i]);

                byte[,] tempCoords = new byte[bitmap.Width, bitmap.Height];

                for (int x = 0; x < bitmap.Width; x++)
                {
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        Color pixel = bitmap.GetPixel(x, y);
                        if (pixel.A == 1)
                        {
                            //hm
                        }
                        ConsoleColor consoleColor = NearestConsoleColor.ClosestConsoleColor(pixel.R, pixel.G, pixel.B);
                        tempCoords[x, (bitmap.Height - y) - 1] = (byte)consoleColor;
                    }
                }
                formatter.Serialize(fileStream, tempCoords);
            }
            fileStream.Close();
        }
Esempio n. 2
0
        public static void BMPToCframe(string pathToBMP, string pathToWrite)
        {
            IFormatter formatter = new BinaryFormatter();
            Bitmap     bitmap    = (Bitmap)Image.FromFile(pathToBMP);

            byte[,] tempCoords = new byte[bitmap.Width, bitmap.Height];
            FileStream fileStream = new FileStream(pathToWrite, FileMode.Create);

            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color        pixel        = bitmap.GetPixel(x, y);
                    ConsoleColor consoleColor = NearestConsoleColor.ClosestConsoleColor(pixel.R, pixel.G, pixel.B);
                    tempCoords[x, (bitmap.Height - y) - 1] = (byte)consoleColor;
                }
            }
            formatter.Serialize(fileStream, tempCoords);
            fileStream.Close();
        }
Esempio n. 3
0
        //TODO: IMPLEMENT TRANSPARENCY INTO CFRAMES
        public static Coords[] BMPToCoords(string pathToBMP)
        {
            Bitmap bitmap = (Bitmap)Image.FromFile(pathToBMP);

            Coords[] coords = new Coords[bitmap.Width * bitmap.Height];
            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color pixel = bitmap.GetPixel(x, y);
                    if (pixel.A == 1)
                    {
                        //nah
                    }
                    else
                    {
                        ConsoleColor consoleColor = NearestConsoleColor.ClosestConsoleColor(pixel.R, pixel.G, pixel.B);
                        coords.Append(new Coords(x, y, ' ', consoleColor, consoleColor));
                    }
                }
            }
            return(coords);
        }