Minggu, 07 Juli 2013

PENGOLAHAN CITRA

0 komentar
Public Class Form1
    Dim gambar As Bitmap
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    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
        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 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 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 2 Step -1
                For pc = .Width - 1 To 2 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 LeftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftToolStripMenuItem.Click
        Pic2.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
        Pic2.Invalidate()
    End Sub

    Private Sub RightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightToolStripMenuItem.Click
        Pic2.Image.RotateFlip(RotateFlipType.Rotate90FlipX)
        Pic2.Invalidate()
    End Sub

    Private Sub HorizontalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HorizontalToolStripMenuItem.Click
        Pic2.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
        Pic2.Invalidate()
    End Sub

    Private Sub ManipulasiCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ManipulasiCitraToolStripMenuItem.Click

    End Sub

    Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click

    End Sub

Labels