public static ConsoleKey ViewColorBuffer(ColorBufferRequest info) { Console.Clear(); Console.SetCursorPosition(0, 0); Console.Write($"{info.PixelPtr}"); var cancellationTokenSource = new CancellationTokenSource(); void _draw_loop() { Point location = new Point(0, 2); Size fontSize = NativeMethods.GetConsoleFontSize(); Size imageSize = new Size(info.Width * info.Scale, info.Height * info.Scale); // desired image size // translate character positions to pixels Rectangle imageRect = new Rectangle( location.X * fontSize.Width, location.Y * fontSize.Height, imageSize.Width, imageSize.Height); while (!cancellationTokenSource.IsCancellationRequested) { Thread.Sleep(100); using (Graphics g = Graphics.FromHwnd(NativeMethods.GetConsoleWindow())) { Image image = GetBufferBitmap(info.Format, info.PixelPtr, info.Width, info.Height); //g.FillRectangle(new SolidBrush(Color.Black), imageRect); g.DrawImage(image, imageRect); } } } Task task = Task.Factory.StartNew(_draw_loop, cancellationTokenSource.Token); ConsoleKey key; do { key = Console.ReadKey().Key; }while (!(key == ConsoleKey.DownArrow || key == ConsoleKey.UpArrow)); cancellationTokenSource.Cancel(); try { Task.WaitAll(task); } catch (AggregateException e) { Console.WriteLine("\nAggregateException thrown with the following inner exceptions:"); // Display information about each exception. foreach (var v in e.InnerExceptions) { if (v is TaskCanceledException) { Console.WriteLine(" TaskCanceledException: Task {0}", ((TaskCanceledException)v).Task.Id); } else { Console.WriteLine(" Exception: {0}", v.GetType().Name); } } Console.WriteLine(); } finally { cancellationTokenSource.Dispose(); } return(key); }
public static ConsoleKey ViewFrameBuffer(N64Ptr ptr) { return(ViewColorBuffer(ColorBufferRequest.GetFramebufferRequest(ptr))); }