Latest Games :

Tugas Program VB (Pengolahan Citra)

Friday, June 28, 2013 | 0 komentar


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 = "JPG|*.jpg|BMP|*.bmp"
        SFD.ShowDialog()
        If SFD.FileName = "" Then Exit Sub
        If SFD.FilterIndex = 1 Then
            gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
        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 Pb, Pc As Integer
        Dim vM, vH, vB As Double
        Dim gambar3 As Bitmap = New Bitmap(Pic1.Image)
        With gambar
            For Pb = .Height - 1 To 0 Step -1
                For Pc = .Width - 1 To 0 Step -1
                    vM = .GetPixel(Pc, Pb).R
                    vH = .GetPixel(Pc, Pb).G
                    vB = .GetPixel(Pc, Pb).B
                    gambar3.SetPixel(.Width - 1 - Pc, .Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
                Next
                Pic2.Image = gambar3
                Pic2.Refresh()
            Next
        End With
        gambar = gambar3
    End Sub

    Private Sub SmoothingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SToolStripMenuItem.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)
        Pic2.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

        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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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).B) * 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.Refresh()
                End If
            Next
        End With
        Pic1.Refresh()
        Me.Text = "Proses Smoothing Image berhasil"
    End Sub

    Private Sub ContrastToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContrastToolStripMenuItem.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 DerajatToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DerajatToolStripMenuItem2.Click
        Dim rgb As Image
        rgb = Pic2.Image
        If rgb IsNot Nothing Then rgb.RotateFlip(RotateFlipType.Rotate270FlipY)
        Pic2.Image = rgb
    End Sub

    Private Sub DerajatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DerajatToolStripMenuItem.Click
        Dim rgb As Image
        rgb = Pic2.Image
        If rgb IsNot Nothing Then rgb.RotateFlip(RotateFlipType.Rotate270FlipX)
        Pic2.Image = rgb
    End Sub

    Private Sub DerajatToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DerajatToolStripMenuItem1.Click
        Dim rgb As Image
        rgb = Pic2.Image
        If rgb IsNot Nothing Then rgb.RotateFlip(RotateFlipType.Rotate180FlipY)
        Pic2.Image = rgb
    End Sub
End Class





Gambar Hasil Program

 Biner.jpg
 
Negatif.jpg

Brigthness.jpg



 Rotate 180 derajad .jpg

 Rotate  90 derajad.jpg
 Grayscale.jpg

 Smooting.jpg


 Rotate 270 derajad.jpg

Contrast.jpg
Continue Reading

Yuk! Belajar Konsep Pemrograman Di Mesran.Blogspot.Com

Sunday, June 2, 2013 | 0 komentar

Selesaikanlah Kasus Berikut :


Buatlah program untuk menampilkan hasil ke listview untuk kasus Latihan Listview Perhitungan Penjualan Barang

 


Berikut Jawaban Program :
 
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "PENJUALAN BARANG"

        Kode.Items.Add("TS001")
        Kode.Items.Add("TS002")
        Kode.Items.Add("VG001")
        Kode.Items.Add("VG002")

        Buattabel()
    End Sub
    Sub Buattabel()
        LV.Columns.Add("No Pembelian", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Kode Barang", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Nama Barang", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Merk", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Harga", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Jumlah Beli", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Total Harga", 80, 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(Kode.Text)
        LST.SubItems.Add(Nama.Text)
        LST.SubItems.Add(Merk.Text)
        LST.SubItems.Add(Harga.Text)
        LST.SubItems.Add(Jumlah.Text)
        LST.SubItems.Add(Total.Text)
        LV.Items.Add(LST)
    End Sub
    Sub smpn(ByVal t As Form)
        No.Text = ""
        Kode.Text = ""
        Nama.Text = ""
        Merk.Text = ""
        Harga.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub

    Private Sub Kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Kode.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Left(Kode.Text, 2)
        Select Case x
            Case "TS" : Merk.Text = "Toshiba"
            Case "VG" : Merk.Text = "V-Gen"
        End Select
        Dim y As String
        y = Microsoft.VisualBasic.Right(Kode.Text, 3)
        Select Case y
            Case "001" : Nama.Text = "Flashdisk 4GB"
            Case "002" : Nama.Text = "Flashdisk 2GB"
        End Select
        Dim z As String
        z = Microsoft.VisualBasic.Mid(Kode.Text, 1)
        Select Case z
            Case "TS001" : Harga.Text = "105000"
            Case "TS002" : Harga.Text = "75000"
            Case "VG001" : Harga.Text = "90000"
            Case "VG002" : Harga.Text = "60000"
        End Select
    End Sub

    Private Sub Btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnproses.Click
        Total.Text = Val(Harga.Text) * Val(Jumlah.Text)
    End Sub
    Private Sub Bntsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bntsimpan.Click
        ISITABEL()
        smpn(Me)
    End Sub

    Private Sub btnhapusdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapusdata.Click
        LV.Items.Remove(LV.SelectedItems(0))
    End Sub

    Private Sub Btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnhapus.Click
        LV.Items.Clear()
    End Sub

    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub

    Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
        No.Text = ""
        Kode.Text = ""
        Nama.Text = ""
        Merk.Text = ""
        Harga.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub
End Class


Continue Reading
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Informasi Dunia Maya - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger