Desain Form Pengolahan Citra
Isi Menu
Listing Program
Public Class Form1
Dim Gambar As Bitmap
Private Sub OpenCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCitraToolStripMenuItem.Click
OFD.Filter = "BMP|*.bmp|JPG|*.Jpg"
OFD.ShowDialog()
If OFD.FileName = "" Then Exit Sub
Pic1.Image = Image.FromFile(OFD.FileName)
Gambar = New Bitmap(Pic1.Image)
End Sub
Private Sub SaveCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveCitraToolStripMenuItem.Click
SFD.Filter = "BMP|*.bmp|JPG|*.Jpg"
SFD.ShowDialog()
If SFD.FileName = "" Then Exit Sub
If SFD.FilterIndex = 1 Then
Gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
If SFD.FilterIndex = 2 Then
Gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
End Sub
Private Sub GrayscaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayscaleToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim Rt, vM, vH, vB As Double
With Gambar
For Pb = 0 To .Height - 1
For Pc = 0 To .Width - 1
vM = .GetPixel(Pc, Pb).R
vH = .GetPixel(Pc, Pb).G
vB = .GetPixel(Pc, Pb).B
Rt = (vM + vH + vB) / 3
.SetPixel(Pc, Pb, Color.FromArgb(Rt, Rt, Rt))
Next
Pic2.Image = Gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub NegatifToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NegatifToolStripMenuItem.Click
Dim pb, pc As Integer
Dim vM, vH, vB As Double
With Gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vM = 255 - .GetPixel(pc, pb).R
vH = 255 - .GetPixel(pc, pb).G
vB = 255 - .GetPixel(pc, pb).B
If vM <= 0 Then vM = 0
If vB <= 0 Then vB = 0
If vH <= 0 Then vH = 0
.SetPixel(pc, pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = Gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub BrigthnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BrigthnessToolStripMenuItem.Click
Dim pb, pc As Integer
Dim vM, vH, vB As Double
With Gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vM = .GetPixel(pc, pb).R + 5
vH = .GetPixel(pc, pb).G + 5
vB = .GetPixel(pc, pb).B + 5
If vM > 255 Then vM = 255
If vB > 255 Then vB = 255
If vH > 255 Then vH = 255
.SetPixel(pc, pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = Gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub DefaultGambarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultGambarToolStripMenuItem.Click
Gambar = New Bitmap(Pic1.Image)
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
End
End Sub
Private Sub BinerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinerToolStripMenuItem.Click
Dim pb, pc As Integer
Dim rata, vM, vH, vB As Double
With Gambar
For pb = 0 To .Height - 1
For pc = 0 To .Width - 1
vM = .GetPixel(pc, pb).R
vH = .GetPixel(pc, pb).G
vB = .GetPixel(pc, pb).B
rata = (vM + vH + vB) / 3
If (rata < 128) Then
vM = 0
vH = 0
vB = 0
Else
vM = 255
vH = 255
vB = 255
End If
.SetPixel(pc, pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = Gambar
Pic2.Refresh()
Next
End With
End Sub
Private Sub RotateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RotateToolStripMenuItem.Click
Dim grb As Image
grb = Pic2.Image
If grb IsNot Nothing Then grb.RotateFlip(RotateFlipType.Rotate90FlipX)
Pic2.Image = grb
End Sub
Private Sub CountrasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CountrasToolStripMenuItem.Click
Gambar = New Bitmap(Pic1.Image)
Pic2.Image = Gambar
Dim tempbmp As New Bitmap(Pic1.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red, Green, Blue As Integer
Dim X, Y As Integer
Dim tc As Integer
tc = 5
With tempbmp
For X = DX To .Height - DX - 1
For Y = DY To .Width - DY - 1
Red = CInt(.GetPixel(Y, X).R)
Green = CInt(.GetPixel(Y, X).G)
Blue = CInt(.GetPixel(Y, X).B)
'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
Red = Red * tc
Blue = Blue * tc
Green = Green * tc
If (Red > 255) Then
Red = 255
End If
If (Blue > 255) Then
Blue = 255
End If
If (Green > 255) Then
Green = 255
End If
Gambar.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
Next
If X Mod 10 = 0 Then
Pic1.Invalidate()
Pic2.Refresh()
End If
Next
End With
End Sub
Private Sub StatementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StatementToolStripMenuItem.Click
Dim MF(2, 2) As Double
'MaskFilter.Show()
'matriks Filter
' 0 1 2
'0 a b c
'1 d e f
'2 g h i
'Filter smoothing
MF(0, 0) = 1 / 9 'a
MF(0, 1) = 1 / 9 'b
MF(0, 2) = 1 / 9 'c
MF(1, 0) = 1 / 9 'd
MF(1, 1) = 1 / 9 'e
MF(1, 2) = 1 / 9 'f
MF(2, 0) = 1 / 9 'g
MF(2, 1) = 1 / 9 'h
MF(2, 2) = 1 / 9 'i
Gambar = New Bitmap(Pic1.Image)
Pic1.Image = Gambar
Dim tempbmp As New Bitmap(Pic1.Image)
Dim DX As Integer = 1
Dim DY As Integer = 1
Dim Red As Integer, Green As Integer, Blue As Integer
Dim i As Integer, j As Integer
Pic1.Width = Pic1.Width
Pic1.Show()
With Gambar
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
'proses matriks filter
'point(j,i)*e --> titik tengah
Red = CInt(.GetPixel(j, i).R) * MF(1, 1)
Green = CInt(.GetPixel(j, i).G) * MF(1, 1)
Blue = CInt(.GetPixel(j, i). * MF(1, 1)
'proses titik tetangga
'point(j-1,i-1)*a--> MF(0,0)--> titik kiri atas
If j - 1 < 1 And i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(0, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i - 1).R) * MF(0, 0))
Green = Green + (CInt(.GetPixel(j - 1, i - 1).G) * MF(0, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i - 1). * MF(0, 0))
End If
'point(j,i-1)*b --> MF(0,1) --> titik atas
If i - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(0, 1))
Else
Red = Red + (CInt(.GetPixel(j, i - 1).R) * MF(0, 1))
Green = Green + (CInt(.GetPixel(j, i - 1).G) * MF(0, 1))
Blue = Blue + (CInt(.GetPixel(j, i - 1). * MF(0, 1))
End If
'point(j+1,i-1)*c --> MF(0,2) --> titik kanan atas
If j + 1 > .Width - DY - 1 And i - 1 > 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(0, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i - 1).R) * MF(0, 2))
Green = Green + (CInt(.GetPixel(j + 1, i - 1).G) * MF(0, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i - 1). * MF(0, 2))
End If
'point(j-1,i)*d --> MF(1,0) --> titik kiri
If j - 1 < 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(1, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i).R) * MF(1, 0))
Green = Green + (CInt(.GetPixel(j - 1, i).G) * MF(1, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i). * MF(1, 0))
End If
'point(j+1,i)*f --> MF(1,2) --> titik kanan
If j + 1 > .Width - DY - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(1, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i).R) * MF(1, 2))
Green = Green + (CInt(.GetPixel(j + 1, i).G) * MF(1, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i). * MF(1, 2))
End If
'point(j-1,i+1)*g --> MF(2,0) --> titik kiri bawah
If j - 1 < 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(2, 0))
Else
Red = Red + (CInt(.GetPixel(j - 1, i + 1).R) * MF(2, 0))
Green = Green + (CInt(.GetPixel(j - 1, i + 1).G) * MF(2, 0))
Blue = Blue + (CInt(.GetPixel(j - 1, i + 1). * MF(2, 0))
End If
'point(j,i+1)*g --> MF(2,1) --> titik bawah
If i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(2, 1))
Else
Red = Red + (CInt(.GetPixel(j, i + 1).R) * MF(2, 1))
Green = Green + (CInt(.GetPixel(j, i + 1).G) * MF(2, 1))
Blue = Blue + (CInt(.GetPixel(j, i + 1). * MF(2, 1))
End If
'point(j+1,i+1)*h --> MF(2,2) --> titik kanan bawah
If j + 1 > .Width - DY - 1 And i + 1 > .Height - DX - 1 Then 'jika out of border ambil nilai tengah/point(x,y)
Red = Red + (CInt(.GetPixel(j, i).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j, i).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j, i). * MF(2, 2))
Else
Red = Red + (CInt(.GetPixel(j + 1, i + 1).R) * MF(2, 2))
Green = Green + (CInt(.GetPixel(j + 1, i + 1).G) * MF(2, 2))
Blue = Blue + (CInt(.GetPixel(j + 1, i + 1). * MF(2, 2))
End If
'normalisasi
If Red < 0 Then
Red = 0
Else
If Red > 255 Then
Red = 255
End If
End If
If Green < 0 Then
Green = 0
Else
If Green > 255 Then
Green = 255
End If
End If
If Blue < 0 Then
Blue = 0
Else
If Blue > 255 Then
Blue = 255
End If
End If
'simpan warna hasil smoothing ke point j,i
Gambar.SetPixel(j, i, Color.FromArgb(Red, Green, Blue))
Next
If i Mod 10 = 0 Then
Pic1.Invalidate()
Me.Text = Int(100 * i / (Pic1.Image.Height - 2)).ToString & "%"
Pic1.Text = Int(100 * i / (Pic1.Image.Height - 2))
Pic1.Refresh()
End If
Next
End With
Pic1.Image = Gambar
Pic1.Refresh()
Me.Text = "Proses Smoothing Image berhasil"
End Sub
End Class
Hasil pengolahan Citra Grayscale
Hasil pengolahan Citra Negatif
Hasil pengolahan Citra Brigthness
Hasil pengolahan Citra Biner
Hasil pengolahan Citra Rotate
Hasil pengolahan Citra Countras
Hasil pengolahan Citra Smoothing
Sekian dan Terima Kasih....
^_^
Rabu, 26 Juni 2013
Minggu, 02 Juni 2013
Yuk! Belajar Pemrograman Visual Basic Dot Net Di Mesran.Net
Latihan Listview Perhitungan Penjualan Barang
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buattabel()
KD.Items.Add(“TS001″)
KD.Items.Add(“TS002″)
KD.Items.Add(“VG001″)
KD.Items.Add(“VG002″)
End Sub
Sub buattabel()
LV.Columns.Add(“NO.PEMBELIAN”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“KODE BARANG”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“NAMA BARANG”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“MERK”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“HARGA”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“JUMLAH BELI”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“TOTAL HARGA”, 100, HorizontalAlignment.Center)
LV.View = View.Details
LV.GridLines = True
LV.FullRowSelect = True
End Sub
Sub IsiTabel()
Dim Lst As New ListViewItem
Lst.Text = NO.Text
Lst.SubItems.Add(KD.Text)
Lst.SubItems.Add(NB.Text)
Lst.SubItems.Add(MERK.Text)
Lst.SubItems.Add(HARGA.Text)
Lst.SubItems.Add(JB.Text)
Lst.SubItems.Add(TH.Text)
LV.Items.Add(Lst)
End Sub
Private Sub KD_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KD.SelectedIndexChanged
Dim x As String
x = Microsoft.VisualBasic.Left(KD.Text, 2)
If x = “TS” Then
MERK.Text = “TOSHIBA”
ElseIf x = “VG” Then
MERK.Text = “V-GEN”
End If
Dim y As String
y = Microsoft.VisualBasic.Mid(KD.Text, 3)
If y = “001″ Then
NB.Text = “FLASHDISK 4GB”
ElseIf y = “002″ Then
NB.Text = “FLASHDISK 2GB”
End If
Dim z As String
z = Microsoft.VisualBasic.Left(KD.Text, 5)
If z = “TS001″ Then
HARGA.Text = “105000″
ElseIf z = “TS002″ Then
HARGA.Text = “75000″
ElseIf z = “VG001″ Then
HARGA.Text = “90000″
ElseIf z = “VG002″ Then
HARGA.Text = “60000″
End If
End Sub
Private Sub JB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JB.TextChanged
TH.Text = HARGA.Text * JB.Text
End Sub
Private Sub JB_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles JB.KeyPress
Dim TOMBOL As Integer = Asc(e.KeyChar)
If TOMBOL = 13 Then
BTNSIMPAN_Click(sender, e)
End If
End Sub
Private Sub BTNSIMPAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNSIMPAN.Click
IsiTabel()
NO.Text = ” “
KD.Text = ” “
NB.Text = ” “
MERK.Text = ” “
HARGA.Text = ” “
JB.Text = ” “
TH.Text = ” “
End Sub
Private Sub BTNHAPSEM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNHAPSEM.Click
LV.Items.Clear()
End Sub
Private Sub BTNHAPDAT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNHAPDAT.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
Private Sub BTNBERSIH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNBERSIH.Click
NO.Text = ” “
KD.Text = ” “
NB.Text = ” “
MERK.Text = ” “
HARGA.Text = ” “
JB.Text = ” “
TH.Text = ” “
End Sub
Private Sub BTNKELUAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNKELUAR.Click
End
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buattabel()
KD.Items.Add(“TS001″)
KD.Items.Add(“TS002″)
KD.Items.Add(“VG001″)
KD.Items.Add(“VG002″)
End Sub
Sub buattabel()
LV.Columns.Add(“NO.PEMBELIAN”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“KODE BARANG”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“NAMA BARANG”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“MERK”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“HARGA”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“JUMLAH BELI”, 100, HorizontalAlignment.Center)
LV.Columns.Add(“TOTAL HARGA”, 100, HorizontalAlignment.Center)
LV.View = View.Details
LV.GridLines = True
LV.FullRowSelect = True
End Sub
Sub IsiTabel()
Dim Lst As New ListViewItem
Lst.Text = NO.Text
Lst.SubItems.Add(KD.Text)
Lst.SubItems.Add(NB.Text)
Lst.SubItems.Add(MERK.Text)
Lst.SubItems.Add(HARGA.Text)
Lst.SubItems.Add(JB.Text)
Lst.SubItems.Add(TH.Text)
LV.Items.Add(Lst)
End Sub
Private Sub KD_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KD.SelectedIndexChanged
Dim x As String
x = Microsoft.VisualBasic.Left(KD.Text, 2)
If x = “TS” Then
MERK.Text = “TOSHIBA”
ElseIf x = “VG” Then
MERK.Text = “V-GEN”
End If
Dim y As String
y = Microsoft.VisualBasic.Mid(KD.Text, 3)
If y = “001″ Then
NB.Text = “FLASHDISK 4GB”
ElseIf y = “002″ Then
NB.Text = “FLASHDISK 2GB”
End If
Dim z As String
z = Microsoft.VisualBasic.Left(KD.Text, 5)
If z = “TS001″ Then
HARGA.Text = “105000″
ElseIf z = “TS002″ Then
HARGA.Text = “75000″
ElseIf z = “VG001″ Then
HARGA.Text = “90000″
ElseIf z = “VG002″ Then
HARGA.Text = “60000″
End If
End Sub
Private Sub JB_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JB.TextChanged
TH.Text = HARGA.Text * JB.Text
End Sub
Private Sub JB_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles JB.KeyPress
Dim TOMBOL As Integer = Asc(e.KeyChar)
If TOMBOL = 13 Then
BTNSIMPAN_Click(sender, e)
End If
End Sub
Private Sub BTNSIMPAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNSIMPAN.Click
IsiTabel()
NO.Text = ” “
KD.Text = ” “
NB.Text = ” “
MERK.Text = ” “
HARGA.Text = ” “
JB.Text = ” “
TH.Text = ” “
End Sub
Private Sub BTNHAPSEM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNHAPSEM.Click
LV.Items.Clear()
End Sub
Private Sub BTNHAPDAT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNHAPDAT.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
Private Sub BTNBERSIH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNBERSIH.Click
NO.Text = ” “
KD.Text = ” “
NB.Text = ” “
MERK.Text = ” “
HARGA.Text = ” “
JB.Text = ” “
TH.Text = ” “
End Sub
Private Sub BTNKELUAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNKELUAR.Click
End
End Sub
End Class
Langganan:
Postingan (Atom)