I'm looking for a way to draw an image inside a console window. Similar to how I can call Console.Write("this will display in the console window");
. I'm not sure if this is possible or not.
I've played around a little bit without any luck (probably because .NET wants you to use winforms for graphical programming).
Here's a snippet of what I'm trying to do:
using System;
using System.Drawing;
namespace DisplayImage
{
class Program
{
static void Main(string[] args)
{
using (var bmp = new Bitmap(100, 100))
using (var gr = Graphics.FromImage(bmp))
{
gr.FillRectangle(Brushes.Orange, new Rectangle(0, 0, bmp.Width, bmp.Height));
Console.WriteLine("draw image");
gr.DrawImage(bmp, 1, 1);
Console.WriteLine("drew image");
}
}
}
}
Is there a way to do this?
Is there a way to manipulate pixels in a console app? perhaps I could manually read pixels out of an image and draw each individual pixel in a console.
This is just for fun, btw. Not a practical project, just an exercise/exploratory project. Let's hack the console :-)
No. You could start a separate dialog/window, however. Console applications are used primarily for text only applications. There is no way to display an image.
In C# you can write or print to console using Console. WriteLine() or Console. Write(), basically both methods are used to print output of console.
Actually, the answer is "Yes it is, sort of". Take a look at Drawing in a Win32 Console on C++? for native code for drawing on top of the console window.
To do this with C#, you'd most likely need to call down into native code to do the actual work.
And you wouldn't really be drawing in the console window itself, only into a window drawn above it (a subtle, but potentially important difference).
No. It is not possible to draw to the console window. It supports text only. The closest you will get is ASCII art! I would recommend WPF app for graphics
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With