How display an image/pictures on cmd screen?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

How display an image/pictures on cmd screen?

#1 Post by tcpman » 13 Sep 2014 06:06

i saw that some pepole do this kinda thing's in batch
i was thinking how it's possible to do this ?




also is there any way to convert bat to exe?
as you know if you have a complex code it wont work!
but it should work
because when we run a bat file that we convert it to exe in process list we see cmd.exe not the name of program that we runed

for exmaple
dostips.bat>convert to exe file>dostips.exe

now
dostips.bat>process list>cmd.exe>dostips.exe>process list>cmd.exe

so why bat file's that we convert dont work correctly?
i use bat to exe convertor 1.5
they should work the same because even when we convert it to exe it's run the batch file

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: How display an image/pictures on cmd screen?

#2 Post by einstein1969 » 13 Sep 2014 06:42

I know various methods. These are BASE methods.

FAST:
use Carlos's utility BG/SPRITE. I haven't used for my project, but this is good for colored games.

BG.EXE

SLOW:
use the Carlos's "color" function: Color version 22

but there are other methods...

einstein1969

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: How display an image/pictures on cmd screen?

#3 Post by einstein1969 » 13 Sep 2014 06:52

In this link you can see how work the dos batch function "color"

einstein1969

aGerman
Expert
Posts: 3873
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How display an image/pictures on cmd screen?

#4 Post by aGerman » 13 Sep 2014 07:01

tcpman wrote:i saw that some pepole do this kinda thing's in batch
i was thinking how it's possible to do this ?

If you want to insert an image file then it is not possible unless you would use a 3rd Party Tool that is able to put a picture to the console window. Since the console screen buffer is not able to save/recognize picture informations it would be only volatile though. That means it wouldn't be repainted once you scrolled it out of the window and it would be overwritten by any character because a console window doesn't have something like a "background layer".
Regardless such a tool could easily be written in C or any other language where the WinAPI is usable ...

tcpman wrote:they should work the same because even when we convert it to exe it's run the batch file

No they shouldn't. In that case the batch file is created and executed in another directory, the environment was inherited from the executable, and many more things that depend on the implementation of the converter and that are beyond your control. If you want an .exe file my only advice is to learn a compilable programming language.

Regards
aGerman

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: How display an image/pictures on cmd screen?

#5 Post by tcpman » 13 Sep 2014 07:18

tnx

ok so if we use carlos extenal tool we dont get into any buffer or something problem?


and guys just someone posted this in a forum i think this will solve the bat to exe problem

http://www.f2ko.de/programs.php?lang=en&pid=ob2e

i run it and there was no cmd.exe process
i think this may handle complex code's too if anyone can try it to see what it can do with complex code's plz do it

aGerman
Expert
Posts: 3873
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How display an image/pictures on cmd screen?

#6 Post by aGerman » 13 Sep 2014 07:40

Forget about it. I wrote a very simple code:
test.bat

Code: Select all

@echo off &setlocal
echo "%~f0"
pause

Then I converted it to "test.exe", saved it to my desktop, and executed it.
The result is ...

Code: Select all

"C:\Users\steffen\AppData\Local\Temp\1\test.bat"
Drücken Sie eine beliebige Taste . . .

... while I would expect to see "C:\Users\steffen\Desktop\test.exe".
Again: Keep batch files as they are! You can NEVER make sure that a converted batch file behaves like the script.

Regards
aGerman

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: How display an image/pictures on cmd screen?

#7 Post by tcpman » 13 Sep 2014 07:51

well agerman i think this mean it will work with complex code but there is a chance to make some problem's because of diffrent path

the exe file make a bat file in local temp and then run it!
and save the result in The current exe file!

aGerman
Expert
Posts: 3873
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How display an image/pictures on cmd screen?

#8 Post by aGerman » 13 Sep 2014 08:21

tcpman wrote:well agerman i think this mean it will work with complex code

What let you believe it would?
I don't change my mind because I gained too many horrible experiences with such tools. Finally it's your decision though. All I can do is explicitely warn you. Don't complain if code that you wrote doesn't work as expected after converting. It's always a gambler's game.

Regards
aGerman

tcpman
Posts: 53
Joined: 05 Mar 2014 15:01

Re: How display an image/pictures on cmd screen?

#9 Post by tcpman » 13 Sep 2014 08:33

tnx agerman you are correct
but see
this will make a bat file!
and the bat file is the same bat file that we give to the program!

now if we dont want to do anything with path things (like %0)

it should work! right?

but i have an idea that may cause less problems and solve some of path problems! i send my idea to the programmer of this software
i am wating to see what he says!

ShadowThief
Expert
Posts: 964
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How display an image/pictures on cmd screen?

#10 Post by ShadowThief » 13 Sep 2014 19:10

There's no reason to ever convert a bat file to exe. I don't understand why so many people seem to think this is something worth doing.

carlos
Expert
Posts: 501
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: How display an image/pictures on cmd screen?

#11 Post by carlos » 13 Sep 2014 21:02

ShadowThief wrote:There's no reason to ever convert a bat file to exe. I don't understand why so many people seem to think this is something worth doing.


Yes, the "batch language" is a interpreted "language" by cmd.exe and cmd.exe not accept other input than a text file.
Because this, any batch "compiler" put a plain text file with the code. cmd.exe always will read a plain text file.
The executed code is plain text not machine code. Cmd.exe only accept it, unlike 4dos that accept a encoded batch file (.btm extension) that anyways can be decoded to original source code (using the decode routine from 4dos source code). In conclusion, you not protect anything using a "batch compiler".

aGerman
Expert
Posts: 3873
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How display an image/pictures on cmd screen?

#12 Post by aGerman » 14 Sep 2014 04:02

I tell you a story what could happen even if you think everything is OK.

Once upon the time ...
I created an excel file that was able to collect and compute a lot of exported data from different data bases at work. The result was an analysis of faulty pcs. packed into an excel sheet with the ability to sort them, filter them, show them in different charts etc.
My boss was keen to distribute that file to the supervisors and foremen at the production floor and asked me to find a way to make it accessible for all the guys who influence the quality of our products...
The problem I had to solve was how to make sure all these guys will always work with the latest version of the file, how to make sure that different people are able to work with it at the same time (normally excel shheets are locked or read-only once they were opened) and how to make sure they can't damage the file where it would be unusable for the whole team.
I decided they should make a local copy of the file to their computers. For that reason I wrote a simple batch file that automatically connected the computer to the server share, copied the file and run it.
I also thought it would be a good idea to convert the batch file to become an .exe. I already knew the side effects. I also knew how it works and that it doesn't hide the code. But that was no problem at all because all I wanted to do was protecting the file from inadvertently changing and I was able to give it a meaningful icon.
I distributed that small .exe file to a lot of guys and everything worked like a charm. It saved a lot of money because it shortened the reaction time tremendously.
What I didn't know was that the .exe file was redistributed by the foremen to almost every computer on the production floor. Our employees were requested to check it in the second shift and night shift as well.

One day (round about one year later) I came to my desk in the morning and was surprized to see my boss already discussing with the local administrators and some other guys waiting for me. Somewhen at night an update of our antivirus came in and after that the .exe file was detected as false positive. Dozends of computers fired alert messages to the super administrators of our multinational company. Because of that they thought it was a virus that spreads very rapidly. In the mean time they found out that it was a file that I distributed. You can't imagine the inconveniences I got. I had to explain exactly what the file is for, what the source code did, where I found the converter, why I had the crazy idea to use it in the companys network etc. They sent the file out for analyzing whether or not it was a real malware...

Finally it all came to a good end. But believe me I learned my lessons concerning Bat2Exe and the like ...

Regards
aGerman

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: How display an image/pictures on cmd screen?

#13 Post by foxidrive » 14 Sep 2014 04:32

aGerman wrote:I had to explain exactly what the file is for, what the source code did, where I found the converter, why I had the crazy idea to use it in the companys network etc.


If they bosses didn't like you then it would have been an excuse to let you go.
Good thing it was all sorted out in the end.

aGerman
Expert
Posts: 3873
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How display an image/pictures on cmd screen?

#14 Post by aGerman » 14 Sep 2014 04:48

Yes indeed that was one of my fears. Fortunately I'm on good terms with my boss and he didn't forget the money and time the company saved because of my excel tool.

einstein1969
Expert
Posts: 776
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: How display an image/pictures on cmd screen?

#15 Post by einstein1969 » 14 Sep 2014 06:28

For show an image/picture it's possible use a (SLOW) batch file that read the file and than maps the colors of the image with the color used in the cmd command windows.

It's possible prepare the image for best visualize in a dos batch windows or not prepare.

If you prepare the code for reading and mapping the colors are few.

The dos batch windows can display many colors.

In this link i show how it's possible show UNIFORM colors (FLAT).

and this link show a program that read portable image format (PPM) with no mapping colors (partial mapping).

the code

Code: Select all

@echo off & setlocal EnableDelayedExpansion

call :init_color_fast

rem Legge L'HEADER. Solo file a colori(P3) o grayscale(P2)

rem conversione p3 imagemagik: convert mona.png -resize 154x106! -compress none mona1.ppm
rem per la dimensione usare in asse X multipli della coda findstr=8

set l=1

(

  For /f "eol=# tokens=*" %%f in (%~1) do (

   rem echo(DEBUG:%%f

   if !l! equ 1 (
      set MAGIC=%%f
      if not "!MAGIC!"=="P2" if not "!MAGIC!"=="P3" (echo Not supported format[!MAGIC!].&goto :eof)
      if "!MAGIC!"=="P2" (set BPP=1) else (set BPP=3)
        ) else (
      rem verificare se sono su due righe separate.
      if !l! equ 2 (
         For /f "tokens=1-2" %%p in ("%%f") do set /a WIDTH=%%p, HEIGHT=%%q
      ) else (
         if !l! equ 3 set MAXVALUE=%%f
      )
   )
   set /a l+=1
        if !l! equ 4 goto :body
   
  )

)

:body

echo MAGIC=!MAGIC! BPP=!BPP!
echo WIDTH=!WIDTH! HEIGHT=!HEIGHT!
echo MAXVALUE=!MAXVALUE!

pause

type nul > %tmp%\txt.$$$.txt

rem questo e' il metoto più veloce di leggere e scrivere su file

set t0=%time%

set /a l=0, t=-1, x=0, y=0
(
 
  For /f "eol=# tokens=* skip=3" %%f in (%~1) do (

   for %%g in (%%f) do (
      set /a "t=(t+1) %% 3"
      if !t! equ 0 set R=%%g
      if !t! equ 1 set G=%%g
      if !t! equ 2 (

         rem echo Plot R:!R! G:!G! B:%%g

rem To get luminance of a color use the formula recommended by CIE:
rem L = 0.2126·R + 0.7152·G + 0.0722·B CCIR 709 RGB
rem L'= 0.3*R' + 0.59*G' + 0.11*B' dove R' G' B' sono i valori gamma-corretti e L' e' luminanza gamma-corretta.

         rem if !my! equ 0 if !mx! equ 0 (
            set /A "Lu=(R*2126+G*7152+B*722)/10000"
            rem indice gradiente : 9 10 11 12 5 13 4 14 15 3 8 7 6 1
            If !Lu! gtr 180 (call :color_fast 09 "°") else If !Lu! gtr 160 (call :color_fast 0a "°") else If !Lu! gtr 140 (call :color_fast 0b "°") else If !Lu! gtr 130 (call :color_fast 0c "°") else If !Lu! gtr 115 (call :color_fast 05 "°") else If !Lu! gtr 105 (call :color_fast 0d "°") else If !Lu! gtr 90 (call :color_fast 04 "°") else If !Lu! gtr 80 (call :color_fast 0e "°") else If !Lu! gtr 65 (call :color_fast 0f "°") else If !Lu! gtr 55 (call :color_fast 03 "°") else If !Lu! gtr 45 (call :color_fast 08 "°") else If !Lu! gtr 35 (call :color_fast 07 "°") else If !Lu! gtr 25 (call :color_fast 06 "°") else call :color_fast 01 " "
            if !lu! gtr !maxLu! set /a maxlu=Lu
         rem )

         set /a "x=x+1, mx=x %% 2"
         if !x! geq !WIDTH! (set /a "x=0, y+=1, my=y %% 2" & echo()
         rem if !my! equ 0 echo()
      )
        )

   set /a "l+=1, m=l %% 100"
        if !m! equ 0 title !l! !x!x!y! !Lu! !maxLu!

   rem if !l! gtr 3 goto :eof

  )

)
rem )>>%tmp%\txt.$$$.txt

rem echo(!l!:%%f
rem if !l! gtr 3 goto :eof

for /f "tokens=1-8 delims=:.," %%a in ("%t0: =0%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"

echo %a% cs

rem fc %1 %tmp%\txt.$$$.txt

goto :eof

:color_fast %1=color %2=string
(

    set str=%~2
    set color=%~1
    rem prima accoda e memorizza la stringa e il colore. Fare flush.

    set "color_str[!color_coda!]=!str!"
   
    set "color_c[!color_coda!]=!color!"

    rem mentre accodo potrei fare la compressione dei colori ed evitare di farlo nell'if che segue. DA FARE

    if !color_coda! equ !color_lcm1! (

      rem se il colore e' invariato può unire le stringhe e fare una sola chiamata

      rem unisco le stringhe e le metto nei file

      set /a da=0, count=-1
      set str=
      for /L %%c in (0,1,!color_len_coda!) do (
   
   for %%d in (!da!) do if not "!color_c[%%d]!"=="!color_c[%%c]!" (
      
      rem set /a a=%%c-1, da=%%c, count+=1
      set /a da=%%c, count+=1
      echo(!str!\..\'>%color_$$$%_$$$.color!count!.txt

      rem salvo in variabili i colori compressi per la successiva chiamata con il findstr.
      set color_c[!count!]=!color_c[%%d]!

      rem echo da:%%d a:!a! next=!da! color:!color_c[%%d]! str=!str!
      set str=

   )
        set str=!str!!color_str[%%c]!
   rem echo !da! %%c
      )

      rem chiamo i findstr necessari, dati da count.

      for /L %%e in (0,1,!count!) do findstr /a:!color_c[%%e]! /f:%color_$$$%_$$$.color%%e.txt "."

    )

    set /a "color_coda=(color_coda+1) %% !color_len_coda!"

goto :eof
)

:init_color_fast

rem mi sposto nella directory temporanea
rem pushd %tmp%

rem creo il carattere DEL
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "DEL=%%a"

rem creo carattere condiviso '
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"

rem creo identificativo univoco sessione
set color_$$$=%random%_%random%

rem contatore buffer
set color_coda=0

rem lunghezza coda
set /a color_len_coda=64, color_lcm1=color_len_coda-1


goto :eof




EDIT : added link to rainbow FLAT colors

einstein1969

Post Reply