0

I am attempting to draw images to the console that overlap however the code I am using creates space characters when there is white to shift the cursor however this means that where there is blank space in the image it writes over the character already there.

The Script

using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace ConsoleImage
{
    class Program
    {
        static void Main(string[] args)
        {
            Image Picture = Image.FromFile(@"C:\Users\InfoKriegerX\Pictures\your_image.jpg");
            Console.SetBufferSize((Picture.Width * 0x2), (Picture.Height * 0x2));
            FrameDimension Dimension = new FrameDimension(Picture.FrameDimensionsList[0x0]);
            int FrameCount = Picture.GetFrameCount(Dimension);
            int Left = Console.WindowLeft, Top = Console.WindowTop;
            char[] Chars = { '#', '#', '@', '%', '=', '+', '*', ':', '-', '.', ' ' };
            Picture.SelectActiveFrame(Dimension, 0x0);
            for (int i = 0x0; i < Picture.Height; i++)
            {
                for (int x = 0x0; x < Picture.Width; x++)
                {
                    Color Color = ((Bitmap)Picture).GetPixel(x, i);
                    int Gray = (Color.R + Color.G + Color.B) / 0x3;
                    int Index = (Gray * (Chars.Length - 0x1)) / 0xFF;
                    Console.Write(Chars[Index]);
                }
                Console.Write('\n');
            }
            Console.SetCursorPosition(Left, Top);
            Console.Read();
        }
    }
}

I have attempted to shift the console cursor right one instead of writing a blank character however this malforms the console output.

   if (Chars[Index].Equals(" ")) { Console.SetCursorPosition(Console.WindowLeft + 1, Console.WindowTop); }
                    else
                    {
                        Console.Write(Chars[Index]);
                    }
  • If the image overlap, overwriting previous 'pixels' seems quite natural, no? – TaW Aug 11 '18 at 12:24
  • @TaW The issue here is the blank space of the image is printed as a space character and this overrides the previous 'pixels'. Effectively transparency is overriding a 'solid pixel' on the new draw. – StevenHughes Aug 11 '18 at 12:49
  • Ah, right. In that case you need to combine the images before as afaik you can't read a character from the screen once it is out there.. (otoh some posts [here](https://stackoverflow.com/questions/12355378/read-from-location-on-console-c-sharp) offer complicated workarounds..) – TaW Aug 11 '18 at 13:09
  • @TaW I can read what is placed though since my script manually places them. Combining the images would be a workaround but isn't a great option for scalability reasons. (I suggest you read over the script and try it) – StevenHughes Aug 11 '18 at 13:16

0 Answers0