Photo to ASCII-art converter
This code converts picture files to .TXT files. Works best with photo's. Start a new project, insert a picturebox, and past the code in the code-window, HAVE FUN !!
Original Author: Sneechy
Inputs
You need a picture file (I only tested with .BMP's and .JPG's)
Assumptions
There is an API used in this one, to get the colorcode from a pixel on the screen, if you search on the Internet for a while, you'll find an explanation of how to use this API. (don't ask me about it)
Returns
A file on the desktop called picture.txt
Code
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Load()
Me.Top = 0
Me.Left = 0
Picture1.ScaleMode = 3
Picture1.Top = 0
Picture1.Left = 0
Picture1.AutoSize = True
Picture1.Picture = LoadPicture("c:windowsdesktop" & InputBox("What picture do you want to convert ? c:windowsdesktop", "Pic2txt"))
Me.Width = Picture1.Width + 120
Me.Height = Picture1.Height + 405
Me.Show
Dim x As Integer
Dim y As Integer
Dim tempcolor As Long
Open "c:windowsdesktoppicture.txt" For Output As #1
For y = 1 To Picture1.ScaleHeight Step 2
For x = 1 To Picture1.ScaleWidth - 1
tempcolor = GetPixel(Picture1.hdc, x, y)
Print #1, Mid("#iex+..", Int((Int(tempcolor / 65536) + Int((tempcolor - Int(tempcolor / 65536) * 65536) / 256) + tempcolor - Int(tempcolor / 256) * 256) / 3 / 42.5) + 1, 1);
Next x
Picture1.PSet (2, y), vbRed
Print #1, ""
Next y
Close #1
MsgBox "Your picture is converted to: C:WINDOWSDESKTOPPICTURE.TXT, use Wordpad to open it, Select All, set font size to 3, scroll up, and see what it has been converted to.", vbOKOnly, "Pic2txt"
End Sub
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.