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 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 BrightnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrightnessToolStripMenuItem.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 + 5
vh = 255 - .GetPixel(pc, pb).G + 5
vb = 255 - .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 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
Tidak ada komentar:
Posting Komentar