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
vM = (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 BeighToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeighToolStripMenuItem.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 = gambar
pic2.Refresh()
Next
End With
gambar = gambar3
End Sub
End Class
0 komentar:
Posting Komentar