Image to String, String to Image #2
*
Option Strict On
Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Dim Bild As Bitmap
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
CheckForIllegalCrossThreadCalls = False

Dim width As Integer = CInt(RichTextBox1.Text.Split(CChar("|"))(1).Split(CChar("*"))(0))
Dim height As Integer = CInt(RichTextBox1.Text.Split(CChar("|"))(1).Split(CChar("*"))(1))
Bild = New Bitmap(width, height)

RichTextBox1.Text = RichTextBox1.Text.Split(CChar("|"))(0)

For Each line In RichTextBox1.Lines
ProgressBar1.Maximum = width * height
BackgroundWorker1.ReportProgress(width * height)

Dim farbe As String = line.Split(CChar("'"))(0)
Dim R, G, B, A As Integer
Dim Geteilt() As String = farbe.Split(CChar("-"))

R = CInt(Geteilt(0))
G = CInt(Geteilt(1))
B = CInt(Geteilt(2))
A = CInt(Geteilt(3))

Dim x As Integer = CInt(CDbl(line.Split(CChar("'"))(1).Split(CChar(","))(0)))
Dim y As Integer = CInt(CDbl(line.Split(CChar("'"))(1).Split(CChar(","))(1)))

Dim c As Color = Color.FromArgb(A, R, G, B)
Bild.SetPixel(CInt(x) - 1, CInt(y) - 1, c)
PictureBox1.Image = Bild
Next
End Sub

Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Bild.Save("C:\User\" & Environment.UserName & "\Desktop\pic.jpg")
End Sub
End Class

1111.PNG

이 게시물을

공유하기

SEARCH

MENU NAVIGATION