How can I display images on the output screen using ASCII code in C++?

1.9k views Asked by At

Note---- I use BORLAND TURBO C++

I know that Turbo C++ is two decades old, and it does not support the latest C++ standard either. But since our school still uses it to teach students C++, I can't use any other compiler.

I want to display an image in Turbo C++ using ASCII text. I have already converted the image to ASCII code using an online converter. What should I do now to display it in my program?

I was thinking of something along these lines-

  1. Copy the ASCII code to a txt file.
  2. Read the text file using the getline function.
  3. Display it on the output screen.

I thought it would work, but the difficulty arises when I copy the ASCII image to notepad. It destroys all the formatting of the ASCII image, and the image just becomes a rectangular block of text.

Is there any other way to achieve this? I do not want to use any other libraries if I can help it. I use the graphics.h library in Turbo C++. Also, I am a bit new to C++ (started learning it last year), so I would be grateful if you keep the answers as simple as possible.

2

There are 2 answers

2
Simon On

Well, the first option is to find another online converter which gives you a raw, copy-able, output. In that case you can use your approach.

The second way is to build an ascii converter yourself. The way I think the online tools convert an image into ascii characters is the following:

Build a table with relative brightness, so: space is 0 brightness, 8 = 60% brightness 0 is 80% birghtness # is 90% brightness and go on like this.

  1. Divide the image into blocks (for example 10*10 pixels)
  2. Determine the average brightness of such a block
  3. Find an ascii-character with approximately the same relative brightness.
  4. print image.

this is more complicated, and if you are new you could probably try your approach first.

0
Dragon_Slayer On

It seems that I was copying the text into notepad the wrong way. The get-text option worked fine. I was able to copy the ascii image into notepad and display it in my program.