Desain Form
Imports System.Drawing.BitmapCara Menggunakan :
Public Class Form1
Dim gambar2 As Bitmap
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.Title = "Pilih gambar"
OpenFileDialog1.Filter = "JPEG File |*.jpg;*.jpeg"
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
minHijau.Enabled = False
plusHijau.Enabled = False
grayscale.Enabled = False
minMerah.Enabled = False
plusMerah.Enabled = False
minBrightness.Enabled = False
plusBrightness.Enabled = False
rotate.Enabled = False
negatif.Enabled = False
End Sub
Private Sub grayscale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grayscale.Click
Dim Pb, Pc As Integer
Dim Rt, vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
Rt = (vM + vH + vB) / 3
gambar2.SetPixel(Pc, Pb, Color.FromArgb(Rt, Rt, Rt))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub minHijau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minHijau.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R
vH = gambar2.GetPixel(Pc, Pb).G - 1
vB = gambar2.GetPixel(Pc, Pb).B
If vH <= 0 Then vH = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub plusHijau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plusHijau.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R
vH = gambar2.GetPixel(Pc, Pb).G + 10
vB = gambar2.GetPixel(Pc, Pb).B
If vH >= 255 Then vH = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub minMerah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minMerah.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R - 1
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM <= 0 Then vM = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub plusMerah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plusMerah.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R + 10
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
If vM >= 255 Then vM = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub rotate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rotate.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
Dim gambar3 As Bitmap = New Bitmap(PictureBox1.Image)
For Pb = gambar2.Height - 1 To 0 Step -1
For Pc = gambar2.Width - 1 To 0 Step -1
vM = gambar2.GetPixel(Pc, Pb).R
vH = gambar2.GetPixel(Pc, Pb).G
vB = gambar2.GetPixel(Pc, Pb).B
gambar3.SetPixel(gambar2.Width - 1 - Pc, gambar2.Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar3
PictureBox1.Refresh()
Next
End Sub
Private Sub negatif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles negatif.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = 255 - gambar2.GetPixel(Pc, Pb).R
vH = 255 - gambar2.GetPixel(Pc, Pb).G
vB = 255 - gambar2.GetPixel(Pc, Pb).B
If vM <= 0 Then vM = 0
If vH <= 0 Then vM = 0
If vB <= 0 Then vB = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub plusBrightness_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plusBrightness.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R + 5
vH = gambar2.GetPixel(Pc, Pb).G + 5
vB = gambar2.GetPixel(Pc, Pb).B + 5
If vM >= 255 Then vM = 255
If vH >= 255 Then vH = 255
If vB >= 255 Then vB = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub minBrightness_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minBrightness.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
gambar2 = New Bitmap(PictureBox1.Image)
For Pb = 0 To gambar2.Height - 1
For Pc = 0 To gambar2.Width - 1
vM = gambar2.GetPixel(Pc, Pb).R - 5
vH = gambar2.GetPixel(Pc, Pb).G - 5
vB = gambar2.GetPixel(Pc, Pb).B - 5
If vM <= 0 Then vM = 0
If vH <= 0 Then vH = 0
If vB <= 0 Then vB = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
PictureBox1.Image = gambar2
PictureBox1.Refresh()
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog Then
PictureBox1.Image = FromFile(OpenFileDialog1.FileName)
minHijau.Enabled = True
plusHijau.Enabled = True
grayscale.Enabled = True
minMerah.Enabled = True
plusMerah.Enabled = True
minBrightness.Enabled = True
plusBrightness.Enabled = True
rotate.Enabled = True
negatif.Enabled = True
End If
End Sub
End Class
1. Masukkan salah satu gambar yang ingin diolah melalui tombol "Browse"
2. Pilih option yang di inginkan, misalnya Grayscale.
Hasilnya akan seperti ini