using System; using System.IO; namespace IP { class ImageProcessor { static void ReadPBM(String filePath) { TextReader tr = null; try { tr = new StreamReader(filePath); } catch (Exception e) { Console.WriteLine("Error: File not found."); } if (tr.ReadLine().Equals("P1")) //Verify that it is a .pbm image { tr.ReadLine(); //Skip first comment line while (tr.Peek().ToString().Equals("#")) //Skip additional comment lines { tr.ReadLine(); } string temp = tr.ReadLine(); string [] heightwidth = temp.Split(' '); int height = Convert.ToInt32(heightwidth[1]); int width = Convert.ToInt32(heightwidth[0]); char[] theImage = new char[height*width]; Console.WriteLine("Image Width:{0} Image Height:{1}", width, height); tr.ReadBlock(theImage, 0, height * width); Console.WriteLine("Array Contents:\n{0}", new string(theImage)); } else { Console.WriteLine("File is not a valid .pbm file."); } } static void WritePBM(bool [,] imageArray, String filePath) { TextWriter tw = new StreamWriter(filePath); } static void Main(string[] args) { Console.WriteLine("PBM Image Processor"); Console.WriteLine("-------------------"); Console.WriteLine("\n"); Console.WriteLine("Menu: "); Console.WriteLine("1. Read PBM Image"); Console.WriteLine("2. Write PBM Image"); Console.WriteLine("Choice: "); string choice = Console.ReadLine(); if(choice.Equals("1")) { Console.WriteLine("Name of .pbm file: "); string imagePath = Console.ReadLine(); ReadPBM(imagePath); } else if(choice.Equals("2")) { Console.WriteLine("Name of .pbm file:"); string imagePath = Console.ReadLine(); WritePBM(null, imagePath); } } } }