9

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?

Edit

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 :-)

quakkels
  • 11,676
  • 24
  • 92
  • 149
  • If you can do it with the Windows API, then you can do it in C# (mostly). If you can't do it with the Windows API, then you can't do it in C# (mostly). – John Saunders Dec 23 '13 at 15:35
  • No, **by definition**. See [Console Application](http://en.wikipedia.org/wiki/Console_application) vs [Graphical User Interface](http://en.wikipedia.org/wiki/Graphical_user_interface) – Adriano Repetti Dec 23 '13 at 15:37
  • @John Saunders ... in a console app?? – geedubb Dec 23 '13 at 15:37
  • Yes... in a console app... it must've been possible in the past. This is mostly just an exercise/exploratory question. This isn't practical of course. – quakkels Dec 23 '13 at 15:39
  • No, in the past you din't write in the **console** (true even for graphical console emulators) – Adriano Repetti Dec 23 '13 at 15:40
  • You have ***never*** been able to do graphics in the console! What makes you think this was ever possible? Are we even talking about the same thing? – John Saunders Dec 23 '13 at 15:41
  • 1
    If you want to get really tricky you could change the console color with `Console.ForegroundColor` and write a bunch of unicode `full blocks █`. How fun would that be. – Dave Zych Dec 23 '13 at 15:42
  • The console is an emulation of an old-style character-cell terminal. No, you can't manipulate pixels, only characters. – John Saunders Dec 23 '13 at 15:43
  • 1
    @DaveZych It's easier to set the background color. That's what I did. – Kendall Frey Dec 23 '13 at 16:17
  • @davezych not exactly a hi-res solution though;) – geedubb Dec 25 '13 at 08:03

3 Answers3

4

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).

Community
  • 1
  • 1
David Arno
  • 42,717
  • 16
  • 86
  • 131
3

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

geedubb
  • 4,048
  • 4
  • 27
  • 38
0

Interesting thought:

Though Ascii art, the only possible way I can think of, might not be what you had in mind.

http://en.wikipedia.org/wiki/ASCII_art

tjheslin1
  • 1,378
  • 6
  • 19
  • 36