public Image LoadImageCompressed(string imageName) { try { streamReader = new StreamReader(imageName + ".aspic"); } catch { //the provided image name must not exist Console.WriteLine("Error: Image not found"); Console.ReadLine(); return(new Image("Error", 1, 1)); } string[] headerData = streamReader.ReadLine().Split(':'); //reads the header data and splits it into an array Image imageToReturn = new Image(headerData[0], int.Parse(headerData[1]), int.Parse(headerData[2])); //Now, read in the palette data string[] paletteRawData = streamReader.ReadLine().Split(':'); //Split the string up and convert it into an array of Image.Pixel types int paletteSize = paletteRawData.Length; Image.Pixel[] palette = new Image.Pixel[paletteSize - 1]; for (int count = 0; count < paletteSize - 1; count++) { string[] pixelData = paletteRawData[count].Split(','); palette[count] = new Image.Pixel(int.Parse(pixelData[0]), int.Parse(pixelData[1]), int.Parse(pixelData[2])); } //With the palette created, recreate the image from the image data int xPointer = -1; //Where in the 2D array our pointer is located int yPointer = 0; // while (yPointer < imageToReturn.height - 1 && xPointer < imageToReturn.width - 1) { string[] rawData = streamReader.ReadLine().Split(':'); int paletteIndex = int.Parse(rawData[0]); int pixelCount = int.Parse(rawData[1]); for (int count = 0; count < pixelCount; count++) { if (xPointer < imageToReturn.width - 1) { xPointer++; } else { xPointer = 0; yPointer++; } imageToReturn.data[xPointer, yPointer].SetPixel(palette[paletteIndex].fc, palette[paletteIndex].bc, palette[paletteIndex].s); } } streamReader.Close(); return(imageToReturn); }
public void DrawSinglePixel(Image.Pixel pixelToDraw, int x, int y) { Console.SetCursorPosition(x, y); Console.ForegroundColor = (ConsoleColor)pixelToDraw.fc; Console.BackgroundColor = (ConsoleColor)pixelToDraw.bc; switch (pixelToDraw.s) { case 1: Console.Write("░"); break; case 2: Console.Write("▒"); break; case 3: Console.Write("▓"); break; case 4: Console.Write("█"); break; case 5: Console.Write("▄"); break; case 6: Console.Write("▀"); break; case 7: Console.Write("▌"); break; case 8: Console.Write("▐"); break; } }
public Image LoadImageCompressed(string imageName) { try { streamReader = new StreamReader(imageName + ".aspic"); } catch { //the provided image name must not exist Console.WriteLine("Error: Image not found"); Console.ReadLine(); return new Image("Error", 1, 1); } string[] headerData = streamReader.ReadLine().Split(':'); //reads the header data and splits it into an array Image imageToReturn = new Image(headerData[0], int.Parse(headerData[1]), int.Parse(headerData[2])); //Now, read in the palette data string[] paletteRawData = streamReader.ReadLine().Split(':'); //Split the string up and convert it into an array of Image.Pixel types int paletteSize = paletteRawData.Length; Image.Pixel[] palette = new Image.Pixel[paletteSize - 1]; for (int count = 0; count < paletteSize - 1; count++) { string[] pixelData = paletteRawData[count].Split(','); palette[count] = new Image.Pixel(int.Parse(pixelData[0]), int.Parse(pixelData[1]), int.Parse(pixelData[2])); } //With the palette created, recreate the image from the image data int xPointer = -1; //Where in the 2D array our pointer is located int yPointer = 0; // while (yPointer < imageToReturn.height - 1 && xPointer < imageToReturn.width - 1) { string[] rawData = streamReader.ReadLine().Split(':'); int paletteIndex = int.Parse(rawData[0]); int pixelCount = int.Parse(rawData[1]); for (int count = 0; count < pixelCount; count++) { if (xPointer < imageToReturn.width - 1) xPointer++; else { xPointer = 0; yPointer++; } imageToReturn.data[xPointer, yPointer].SetPixel(palette[paletteIndex].fc, palette[paletteIndex].bc, palette[paletteIndex].s); } } streamReader.Close(); return imageToReturn; }