Basic Image Processing denganVisual Basic

Tampilan GUI :

GUI Basic Image Processing (2)

Hasil processing image :

Picture1

Coding :

Public Class Form1

'moving form
Dim x, y As Integer
Dim newpoint As New Point

Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
x = Control.MousePosition.X - Me.Location.X
y = Control.MousePosition.Y - Me.Location.Y
End Sub

'lanjutan moving form
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button = System.Windows.Forms.MouseButtons.Left Then
newpoint = Control.MousePosition
newpoint.X -= x
newpoint.Y -= y
Me.Location = newpoint
Application.DoEvents()
End If
End Sub

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

End Sub

'BROWSE Button
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
OpenFileDialog1.InitialDirectory = "E:\Document"
OpenFileDialog1.Title = "Open Image"
OpenFileDialog1.Filter = "Format|*.bmp;*.gif;*.jpg;*.jpeg"
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
Exit Sub
End If
End Sub

'SAVE Button
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
SaveFileDialog1.Title = "Save Image"
SaveFileDialog1.Filter = "Format|*.bmp;*.gif;*.jpg;*.jpeg"
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
PictureBox2.Image.Save(SaveFileDialog1.FileName)
Exit Sub
End If
End Sub

'RESET Button
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
'PictureBox2.Image = PictureBox1.Image 'Agar hasil gambar sama dengan gambar asli
PictureBox2.Hide()
End Sub

'ABOUT Button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox("Created by Aprilia, 2018", MsgBoxStyle.OkOnly, "About Program")
End Sub

'GRAYSCALE Button
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim gambar As New Bitmap(PictureBox1.Image) 'Fungsi unt mengubah gambar mjd .bitmap s
PictureBox2.Image = gambar
Dim baris, kolom As Integer
Dim merah, biru, hijau, abu As Integer

PictureBox2.Hide()

'PROGRESS BAR
ProgressBar1.Show()
For baris = 0 To gambar.Width - 1
For kolom = 0 To gambar.Height - 1
merah = gambar.GetPixel(baris, kolom).R
hijau = gambar.GetPixel(baris, kolom).G
biru = gambar.GetPixel(baris, kolom).B

abu = CInt((merah + hijau + biru) / 3) 'Unt mengubah warna RGB menjadi abu-abu / grayscale
gambar.SetPixel(baris, kolom, Color.FromArgb(abu, abu, abu))
Next
If baris Mod 10 = 0 Then
Me.Text = "Progress Grayscale : " & Int(100 * baris / gambar.Width).ToString & "%" 'display persentase di progress bar
ProgressBar1.Value = Int(100 * baris / gambar.Width)
End If
Next
Me.Text = "Progress Done"
ProgressBar1.Hide()
PictureBox2.Refresh()
PictureBox2.Show()
End Sub

'BLACK AND WHITE Button
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim gambar As New Bitmap(PictureBox1.Image) 'Fungsi unt mengubah gambar mjd .bitmap s
PictureBox2.Image = gambar
Dim baris, kolom As Integer
Dim merah, biru, hijau, abu As Integer

PictureBox2.Hide()

'PROGRESS BAR
ProgressBar1.Show()
For baris = 0 To gambar.Width - 1
For kolom = 0 To gambar.Height - 1
merah = gambar.GetPixel(baris, kolom).R
hijau = gambar.GetPixel(baris, kolom).G
biru = gambar.GetPixel(baris, kolom).B

abu = CInt((merah + hijau + biru) / 3) 'Unt mengubah warna RGB menjadi abu-abu / grayscale

If abu < 128 Then
gambar.SetPixel(baris, kolom, Color.FromArgb(0, 0, 0))
Else
gambar.SetPixel(baris, kolom, Color.FromArgb(255, 255, 255))
End If

Next
If baris Mod 10 = 0 Then
Me.Text = "Progress Black and White : " & Int(100 * baris / gambar.Width).ToString & "%" 'display persentase di progress bar
ProgressBar1.Value = Int(100 * baris / gambar.Width)
End If
Next
Me.Text = "Progress Done"
ProgressBar1.Hide()
PictureBox2.Refresh()
PictureBox2.Show()
End Sub

'INVERST Button
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim gambar As New Bitmap(PictureBox1.Image) 'Fungsi unt mengubah gambar mjd .bitmap s
PictureBox2.Image = gambar
Dim baris, kolom As Integer
Dim merah, biru, hijau, abu As Integer

PictureBox2.Hide()

'PROGRESS BAR
ProgressBar1.Show()
For baris = 0 To gambar.Width - 1
For kolom = 0 To gambar.Height - 1
merah = gambar.GetPixel(baris, kolom).R
hijau = gambar.GetPixel(baris, kolom).G
biru = gambar.GetPixel(baris, kolom).B

abu = CInt((merah + hijau + biru) / 3) 'Unt mengubah warna RGB menjadi abu-abu / grayscale
gambar.SetPixel(baris, kolom, Color.FromArgb(255 - merah, 255 - hijau, 255 - biru))
Next
If baris Mod 10 = 0 Then
Me.Text = "Progress Inverst : " & Int(100 * baris / gambar.Width).ToString & "%" 'display persentase di progress bar
ProgressBar1.Value = Int(100 * baris / gambar.Width)
End If
Next
Me.Text = "Progress Done"

ProgressBar1.Hide()
PictureBox2.Refresh()
PictureBox2.Show()
End Sub

'EXIT Button
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Close()
End Sub
End Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.