public void ReadAndRenderFile ( string _filename ) { IAnsiDecoder vt100 = new AnsiDecoder(); //vt100.Encoding = encodingInfo.GetEncoding (); // encodingInfo.Name, new EncoderExceptionFallback(), new DecoderReplacementFallback ("U") ); Screen screen = new Screen ( 80, 160 ); vt100.Subscribe ( screen ); using ( BinaryReader reader = new BinaryReader(File.Open(_filename, FileMode.Open)) ) { try { int read = 0; while ( (read = reader.Read()) != -1 ) { vt100.Input ( new byte[] { (byte) read } ); } } catch ( EndOfStreamException ) { } } System.Console.Write ( screen.ToString() ); Bitmap bitmap = screen.ToBitmap ( new Font("Courier New", 10) ); bitmap.Save ( _filename + ".png", System.Drawing.Imaging.ImageFormat.Png ); }
public Screen ReadAndRenderFile ( string _filename, Encoding _encoding, Size _size ) { IAnsiDecoder vt100 = new AnsiDecoder(); //vt100.Encoding = Encoding.GetEncoding ( encodingInfo.Name, new EncoderExceptionFallback(), new DecoderReplacementFallback ("U") ); vt100.Encoding = _encoding; Screen screen = new Screen ( _size.Width, _size.Height ); vt100.Subscribe ( screen ); using ( Stream stream = File.Open( _filename, FileMode.Open ) ) { try { int read = 0; while ( ( read = stream.ReadByte()) != -1 ) { vt100.Input ( new byte[] { (byte) read } ); } } catch ( EndOfStreamException ) { } } //System.Console.Write ( screen.ToString() ); Bitmap bitmap = screen.ToBitmap ( new Font("Courier New", 6) ); bitmap.Save ( "..\\build\\" + Path.GetFileNameWithoutExtension(_filename) + "_" + _encoding.EncodingName + ".png", System.Drawing.Imaging.ImageFormat.Png ); /* foreach ( Screen.Character ch in screen ) { if ( ch.Char != 0x20 ) { System.Console.WriteLine ( "Non-space character: {0} 0x{1:X4}", ch.Char, (int) ch.Char ); } } */ return screen; }
static int Main( string[] args ) { string inputFilename = null; string outputFilename = null; int width = 80; int height = 25; string fontName = "Courier New"; int fontSize = 6; string encoding = "ibm437"; for ( int i = 0 ; i < args.Length ; i++ ) { switch ( args[i] ) { case "-w": i++; width = Int32.Parse( args[i] ); break; case "-h": i++; height = Int32.Parse( args[i] ); break; case "-f": i++; fontName = args[i]; break; case "-s": i++; fontSize = Int32.Parse( args[i] ); break; case "-e": i++; encoding = args[i]; break; default: if ( inputFilename == null ) { inputFilename = args[i]; } else if ( outputFilename == null ) { outputFilename = args[i]; } else { System.Console.WriteLine( "Unrecognized command line parameter ({0}): {1}", i, args[i] ); } break; } } if ( inputFilename == null || outputFilename == null ) { System.Console.WriteLine( "Syntax:" ); System.Console.WriteLine( " {0} [-w width] [-h height] [-f fontName] [-s fontSize] [-e encoding] <input.txt> <output.png>", System.Reflection.Assembly.GetCallingAssembly().GetName().Name ); return -1; } IAnsiDecoder vt100 = new AnsiDecoder(); Screen screen = new Screen(width, height ); vt100.Encoding = Encoding.GetEncoding( encoding ); vt100.Subscribe( screen ); using ( Stream stream = File.Open( inputFilename, FileMode.Open ) ) { int read = 0; while ( (read = stream.ReadByte()) != -1 ) { vt100.Input( new byte[] { (byte) read } ); } } Bitmap bitmap = screen.ToBitmap( new Font( fontName, fontSize ) ); bitmap.Save( outputFilename, System.Drawing.Imaging.ImageFormat.Png ); return 0; }