protected override Task <int> ExecuteCommand(AboutCommand arguments) { if (VTConsole.IsSupported && !VTConsole.IsEnabled) { VTConsole.Enable(); } var assembly = typeof(AboutCommandHandler).Assembly; using var pngStream = assembly.GetManifestResourceStream( $"{typeof(AboutCommandHandler).Assembly.GetName().Name}.Images.icon-64x64.png" ); VTConsole.SetConsoleWidth80(); using var bitmap = SKBitmap.Decode(pngStream); var builder = new StringBuilder(bitmap.Width * bitmap.Height * 22); for (var j = 0; j < bitmap.Height; j = j + 2) { for (var i = 0; i < bitmap.Width; i++) { var pixel = bitmap.GetPixel(i, j); var str = VTConsole.GetColorBackgroundString(pixel.Red, pixel.Green, pixel.Blue); builder.Append(str); builder.Append(' '); } var backStr = VTConsole.GetColorBackgroundString(0, 0, 0); builder.AppendLine(backStr); } var bytes = Encoding.ASCII.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); if (VTConsole.IsSupported && VTConsole.IsEnabled) { VTConsole.Disable(); } return(Task.FromResult(0)); }
public static void ConsoleWriteImage2(Bitmap bmpSrc) { int sMax = size; decimal percent = Math.Min(decimal.Divide(sMax, bmpSrc.Width), decimal.Divide(sMax, bmpSrc.Height)); Size resSize = new Size((int)(bmpSrc.Width * percent), (int)(bmpSrc.Height * percent)); /*Func<System.Drawing.Color, int> ToConsoleColor = c => * { * int index = (c.R > 128 | c.G > 128 | c.B > 128) ? 8 : 0; * index |= (c.R > 64) ? 4 : 0; * index |= (c.G > 64) ? 2 : 0; * index |= (c.B > 64) ? 1 : 0; * return index; * };*/ Bitmap bmpMin = new Bitmap(bmpSrc, resSize.Width, resSize.Height); Bitmap bmpMax = new Bitmap(bmpSrc, resSize.Width * 2, resSize.Height * 2); var builder = new StringBuilder((resSize.Width + 1) * resSize.Height); for (int i = 0; i < resSize.Height; i++) { string str = ""; for (int j = 0; j < resSize.Width; j++) { str += VTConsole.GetColorForegroundString(bmpMax.GetPixel(j * 2, i * 2).R, bmpMax.GetPixel(j * 2, i * 2).G, bmpMax.GetPixel(j * 2, i * 2).B); str += VTConsole.GetColorBackgroundString(bmpMax.GetPixel(j * 2, i * 2 + 1).R, bmpMax.GetPixel(j * 2, i * 2 + 1).G, bmpMax.GetPixel(j * 2, i * 2 + 1).B); str += "▀"; str += VTConsole.GetColorForegroundString(bmpMax.GetPixel(j * 2 + 1, i * 2).R, bmpMax.GetPixel(j * 2 + 1, i * 2).G, bmpMax.GetPixel(j * 2 + 1, i * 2).B); str += VTConsole.GetColorBackgroundString(bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).R, bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).G, bmpMax.GetPixel(j * 2 + 1, i * 2 + 1).B); str += "▀"; } str += Environment.NewLine; builder.Append(str); } var bytes = Encoding.UTF8.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); }
private static void Example3() { var plasma = new Plasma(256, 256); var width = 80; var height = 40; Console.SetWindowSize(width, height); Console.SetBufferSize(width, height); Console.SetWindowSize(width, height); // removes bars Console.Title = "Plasma !"; Console.CursorVisible = false; var builder = new StringBuilder(width * height * 22); for (var frame = 0; ; frame++) { plasma.PlasmaFrame(frame); builder.Clear(); Thread.Sleep((int)(1.0 / 20 * 1000)); for (var i = 0; i < width * height; i++) { var x1 = i % width; var y1 = i / width; var i1 = y1 * plasma.SizeX + x1; var b = plasma.Screen[i1]; var cr = plasma.ColR[b] >> 4; var cg = plasma.ColG[b] >> 4; var cb = plasma.ColB[b] >> 4; var str = VTConsole.GetColorBackgroundString(cr, cg, cb); builder.Append(str); builder.Append(' '); } var bytes = Encoding.ASCII.GetBytes(builder.ToString()); VTConsole.WriteFast(bytes); } }