Monday 10 June 2013

Pengolahan Citra Untuk Memberi Efek Gambar

Desain Program

Listin Program

Public Class Form2
    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
        PictureBox1.Image = Image.FromFile(OFD.FileName)
        gambar = New Bitmap(PictureBox1.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
        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, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .GetPixel(pc, pb).B
                    rt = (vm + vh + vb) / 3
                    .SetPixel(pc, pb, Color.FromArgb(rt, rt, rt))
                Next
                PictureBox2.Image = gambar
                PictureBox2.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, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = 255 - .GetPixel(pc, pb).R
                    vb = 255 - .GetPixel(pc, pb).G
                    vh = 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, vb, vh))
                Next
                PictureBox2.Image = gambar
                PictureBox2.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, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R + 5
                    vb = .GetPixel(pc, pb).G + 5
                    vh = .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, vb, vh))
                Next
                PictureBox2.Image = gambar

                PictureBox2.Refresh()
            Next
        End With
    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, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .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, vb, vh))
                Next
                PictureBox2.Image = gambar
                PictureBox2.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, vb, vh As Double
        Dim gambar3 As Bitmap = New Bitmap(PictureBox1.Image)
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .GetPixel(pc, pb).B
                   
                    gambar3.SetPixel(.Width - 1 - pc, .Height - 1 - pb, Color.FromArgb(vh, vm, vb))
                Next
                PictureBox2.Image = gambar
                PictureBox2.Refresh()
            Next
        End With
        gambar = gambar3
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gambar = New Bitmap(PictureBox1.Image)
    End Sub

End Class

Semoga Bermanfaat.....google,com
Categories: ,

0 komentar:

Post a Comment