PDA

View Full Version : گفتگو: برنامه تبدیل عکس به متن گرافیکی به عنوان زنگ تفریح



arash020
یک شنبه 16 مهر 1391, 06:05 صبح
سلام

برنامه تبدیل عکس به متن گرافیکی به عنوان زنگ تفریح یا بازی با VS

کنترل های مورد نیاز به کار رفته در سورس برنامه تبدیل عکس به متن گرافیکی :

دوعدد picturebox به نام های:

pic و pic2



یک textbox به نام te

خاصیت multiline true



در ابتدای برنامه

Imports System.IO را بنویسید تا برنامه توانایی ذخیره متن بدست آمده را داشته باشد .



کد زیر را در رویداد کلیک کردن یک دکمه بنویسید و برنامه را اجرا کرده

روی دکمه کلیک کنید و نتیجه را ببینید.



توجه,توجه,توجه:::

حتما باید تصویری که داخل picturebox به نام pic قرار میدهید

یک عکس به ابعاد 50 در 50 پیکسل و کاملا سیاه و سفید باشد

وگرنه باید سورس رو هم تغییر بدید و به اندازه عکس دربیارید

توجه کنید که هرچه اندازه رو بیشتر کنید برنامه زمان بیشتری رو برای انجام عملیات پردازش نیاز داره و برنامه کندتر میشه...

(هنگام طراحی ظاهر برنامه این تصویر را از قبل آماده کرده و کنترل عکس اختصاص دهید .)

برنامه متن بدست آمده را در مسیر

"c:\Eagle computer - Arash020.txt"

ذخیره میکند .



سوالی اگه دارید در قسمت نظر خواهی بپرسید و بعد از 24 ساعت جواب سوالتان را همانجا مشاهده کنید .



سورس:



Dim i, j As Integer

Dim bim As New Bitmap(50, 50)

Dim bim2 As New Bitmap(70, 70)

Dim colo As Color

bim = Pic.Image

For i = 0 To 49

For j = 0 To 49

colo = bim.GetPixel(j, i)



Te.Text = Te.Text & " "

If colo = Color.FromArgb(0, 0, 0) Then

'========

If i > 2 And j > 2 Then

bim2.SetPixel(j, i, colo)



bim2.SetPixel(j + 1, i + 1, colo)



bim2.SetPixel(j - 1, i - 1, colo)



bim2.SetPixel(j + 1, i, colo)



bim2.SetPixel(j, i + 1, colo)



bim2.SetPixel(j - 1, i, colo)



bim2.SetPixel(j, i - 1, colo)



bim2.SetPixel(j - 1, i + 1, colo)



bim2.SetPixel(j + 1, i - 1, colo)

End If



'----------



Te.Text = Te.Text & "//"

End If

Next

Te.Text = Te.Text & vbCrLf

Next

Pic2.Image = bim2

Using ts As New StreamWriter("c:\Eagle computer - Arash020.txt")

ts.Write(Te.Text)

End Using

خـــوش بـــگـــذره...

http://eaglevb.blogfa.com/

arash020
سه شنبه 25 مهر 1391, 02:50 صبح
بفرمایین , ورژن 2وم :

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text
Imports System.Web

Namespace StaticDust

Public Class AsciiArt
Public Shared Function ConvertImage(ByVal stream As Stream, ByVal ImageSize As String, ByVal Quick As String) As String
Dim _asciiart As New StringBuilder()

Dim _img As Image = Image.FromStream(stream)
Dim _image As New Bitmap(_img, New Size(_img.Width, _img.Height))
_img.Dispose()


Dim bounds As New Rectangle(0, 0, _image.Width, _image.Height)

Dim _matrix As New ColorMatrix()

_matrix(0, 0) = 1 / 3.0F
_matrix(0, 1) = 1 / 3.0F
_matrix(0, 2) = 1 / 3.0F
_matrix(1, 0) = 1 / 3.0F
_matrix(1, 1) = 1 / 3.0F
_matrix(1, 2) = 1 / 3.0F
_matrix(2, 0) = 1 / 3.0F
_matrix(2, 1) = 1 / 3.0F
_matrix(2, 2) = 1 / 3.0F

Dim _attributes As New ImageAttributes()
_attributes.SetColorMatrix(_matrix)


Dim gphGrey As Graphics = Graphics.FromImage(_image)
gphGrey.DrawImage(_image, bounds, 0, 0, _image.Width, _image.Height, _
GraphicsUnit.Pixel, _attributes)

gphGrey.Dispose()


Dim _pixwidth As Integer

Select Case ImageSize
Case "1"
If True Then
_pixwidth = 1
Exit Select
End If
Case "2"
If True Then
_pixwidth = 2
Exit Select
End If
Case "4"
If True Then
_pixwidth = 6
Exit Select
End If
Case "5"
If True Then
_pixwidth = 8
Exit Select
End If
Case Else
If True Then
_pixwidth = 3
Exit Select
End If
End Select
Dim _pixhight As Integer = _pixwidth * 2
Dim _pixseg As Integer = _pixwidth * _pixhight

For h As Integer = 0 To _image.Height \ _pixhight - 1

Dim _startY As Integer = (h * _pixhight)

For w As Integer = 0 To _image.Width \ _pixwidth - 1
Dim _startX As Integer = (w * _pixwidth)
Dim _allBrightness As Integer = 0

If Quick = "True" Then

For y As Integer = 0 To _pixwidth - 1
Try
Dim _c As Color = _image.GetPixel(_startX, y + _startY)
Dim _b As Integer = CInt(Math.Truncate(_c.GetBrightness() * 100))
_allBrightness = _allBrightness + _b
Catch
_allBrightness = (_allBrightness + 50)
End Try
Next
Else

For y As Integer = 0 To _pixwidth - 1
For x As Integer = 0 To _pixhight - 1
Dim _cY As Integer = y + _startY
Dim _cX As Integer = x + _startX
Try
Dim _c As Color = _image.GetPixel(_cX, _cY)
Dim _b As Integer = CInt(Math.Truncate(_c.GetBrightness() * 100))
_allBrightness = _allBrightness + _b
Catch
_allBrightness = (_allBrightness + 50)
End Try
Next
Next
End If

Dim _sb As Integer = (_allBrightness \ _pixseg)
If _sb < 10 Then
_asciiart.Append("#")
ElseIf _sb < 17 Then
_asciiart.Append("@")
ElseIf _sb < 24 Then
_asciiart.Append("&")
ElseIf _sb < 31 Then
_asciiart.Append("$")
ElseIf _sb < 38 Then
_asciiart.Append("%")
ElseIf _sb < 45 Then
_asciiart.Append("|")
ElseIf _sb < 52 Then
_asciiart.Append("!")
ElseIf _sb < 59 Then
_asciiart.Append(";")
ElseIf _sb < 66 Then
_asciiart.Append(":")
ElseIf _sb < 73 Then
_asciiart.Append("'")
ElseIf _sb < 80 Then
_asciiart.Append("`")
ElseIf _sb < 87 Then
_asciiart.Append(".")
Else
_asciiart.Append(" ")
End If
Next
_asciiart.Append(vbLf)
Next

_image.Dispose()

Return _asciiart.ToString()

End Function
End Class
End Namespace

amir22448
یک شنبه 21 آبان 1391, 15:11 عصر
سلام میشه برای سیشارپشم بزارید؟

arash020
یک شنبه 21 آبان 1391, 23:13 عصر
سلام دوست عزیز
شما خودت میتونی به راحتی کد بالا یا هر سورس دیگه ای رو به سی شارپ تبدیل کنی و برعکس...
یه سری به وبلاگ
http://eaglevb.blogfa.com/
(http://eaglevb.blogfa.com/)بزن.
برنامه تبدیل سورس اونجا هست .
موفق باشی