Tugas Belajar Belajar Bahasa Pemrograman
Kali ini saya mau memposting tugas kuliah saya tentang pengolahan citra.
Keterangan :
Form 1 : Form Login
Form 2 : Form Pengolahan Citra
Terlebih dahulu membuat Form Loginnya.
Bentuk Form Login
Listing Program Form 1 :
Public Class Form1
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Password.PasswordChar = "*"
End Sub
Private Sub btnOK_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If
Username.Text = "" Or Password.Text = ""
Then
MsgBox("Maaf,
Username Dan Password Belum Di Input!!")
Username.Focus()
ElseIf
Username.Text = "Kristina" And Password.Text = "123"
Then
MsgBox("Selamat
Datang")
Form2.Show()
Me.Hide()
Else
MsgBox("Maaf!
Username Dan Password Salah!")
Username.Text = ""
Password.Text = ""
Username.Focus()
End If
End Sub
Private Sub Password_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
Password.KeyPress
If
Asc(e.KeyChar) = 13 Then
If
Username.Text = "Kristina" And Password.Text = "123"
Then
MsgBox("Selamat
Datang")
Form2.Show()
Me.Hide()
Else
MsgBox("Maaf,
Password yang anda masukkan salah!!")
Username.Text = ""
Password.Text = ""
End
If
End If
End Sub
Private Sub Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Me.Close()
End Sub
Klik double Menustrip :
Listring Program
Private Sub PengolahanCitraToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
PengolahanCitraToolStripMenuItem.Click
Form2.MdiParent = Me
Form2.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KeluarToolStripMenuItem.Click
Me.Close()
End Sub
End Class
Gambar Penggunaan Menustrip
Hasil Login
Selanjutnya buat Form Pengolahan Citranya :
Bentuk Form awal pengolahan citra
Listing Program Form 2 :
Public Class Form2
Dim gambar2
As Bitmap
Private Sub Form2_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PictureBox2.Image = PictureBox1.Image
End Sub
Button 1 : Button - Hijau
Private Sub button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
- 10
Vh = gambar2.GetPixel(Pc, Pb).G
Vb = gambar2.GetPixel(Pc, Pb).B
If
Vm <= 0 Then Vm = 0
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 2 : Button + Hijau
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
+ 10
Vh = gambar2.GetPixel(Pc, Pb).G
Vb = gambar2.GetPixel(Pc, Pb).B
If
Vm >= 255 Then Vm = 255
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 3 : Button Greyscale
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim Pb,
Pc As Integer
Dim Rt,
Vm, Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
Vh = gambar2.GetPixel(Pc, Pb).G
Vb = gambar2.GetPixel(Pc, Pb).B
Rt = (Vm + Vh + Vb) / 3
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Rt, Rt, Rt))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 4 : - Merah
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
+ 5
Vh = gambar2.GetPixel(Pc, Pb).G
+ 5
Vb = gambar2.GetPixel(Pc, Pb).B
+ 5
If
Vm >= 255 Then Vm = 255
If
Vb >= 255 Then Vb = 255
If
Vh >= 255 Then Vh = 255
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 5 : + Merah
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
- 5
Vh = gambar2.GetPixel(Pc, Pb).G
- 5
Vb = gambar2.GetPixel(Pc, Pb).B
- 5
If
Vm <= 0 Then Vm = 0
If
Vb <= 0 Then Vb = 0
If
Vh <= 0 Then Vh = 0
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 6 : Button Rotate
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
Dim
Gambar3 As Bitmap = New
Bitmap(PictureBox1.Image)
For Pb
= gambar2.Height - 1 To 0 Step -1
For
Pc = gambar2.Width - 1 To 0 Step -1
Vm = gambar2.GetPixel(Pc, Pb).R
Vh = gambar2.GetPixel(Pc, Pb).G
Vb = gambar2.GetPixel(Pc, Pb).B
Gambar3.SetPixel(gambar2.Width - 1 - Pc, gambar2.Height - 1 - Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = Gambar3
PictureBox2.Refresh()
Next
End Sub
Button 7 : - Britness
Private Sub Button7_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
Vh = gambar2.GetPixel(Pc, Pb).G
- 10
Vb = gambar2.GetPixel(Pc, Pb).B
If
Vh <= 0 Then Vh = 0
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 8 : + Britness
Private Sub Button8_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = gambar2.GetPixel(Pc, Pb).R
Vh = gambar2.GetPixel(Pc, Pb).G
+ 10
Vb = gambar2.GetPixel(Pc, Pb).B
If
Vh >= 255 Then Vh = 255
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 9 : Button Negativ
Private Sub Button9_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
Dim Pb,
Pc As Integer
Dim Vm,
Vh, Vb As Double
gambar2 = New
Bitmap(PictureBox2.Image)
For Pb
= 0 To gambar2.Height - 1
For
Pc = 0 To gambar2.Width - 1
Vm = 255 - gambar2.GetPixel(Pc,
Pb).R
Vh = 255 - gambar2.GetPixel(Pc,
Pb).G
Vb = 255 - gambar2.GetPixel(Pc, Pb).B
If
Vm <= 0 Then Vm = 0
If
Vb <= 0 Then Vb = 0
If
Vh <= 0 Then Vh = 0
gambar2.SetPixel(Pc, Pb,
Color.FromArgb(Vm, Vh, Vb))
Next
PictureBox2.Image = gambar2
PictureBox2.Refresh()
Next
End Sub
Button 10 : Button Finish
Private Sub Button10_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
End
End Sub
End Class
Dan dibawah ini hasilnya :
Dan dibawah ini hasilnya :
Hasil Button - Hijau
Hasil Button Greyscale
Hasil Button - Merah
Hasil Button + Merah
Hasil Button - Britness
Hasil Button + Britness
Silahkan Mencoba :)
No comments:
Post a Comment
Silahkan tinggalkan komentar dibawah ini. Jadilah pembaca yang aktif. Gomawo ^^