PEMROGRAMAN CITRA SEDERHANA DENGAN VB NET
Public Class Form1
Dim gambar2 As Bitmap
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Pic1.Image = Pic2.Image
End Sub
Private Sub OPENToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OPENToolStripMenuItem1.Click
OFD.Filter = "BMP|*.bmp|JPG|*.jpg"
OFD.ShowDialog()
If OFD.FileName = "" Then Exit Sub
Pic1.Image = Image.FromFile(OFD.FileName)
gambar2 = New Bitmap(Pic1.Image)
End Sub
Private Sub SAVEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SAVEToolStripMenuItem.Click
OFD.Filter = "JPG|*.jpg|BMP|*.bmp"
SFD.ShowDialog()
If OFD.FileName = "" Then Exit Sub
If OFD.FilterIndex = 1 Then
gambar2.Save(OFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
If OFD.FilterIndex = 2 Then
gambar2.Save(OFD.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 gambar2
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
Pic2.Image = gambar2
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 gambar2
For Pb = 0 To .Height - 1
For Pc = 0 To .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 vB <= 0 Then vB = 0
If vH <= 0 Then vH = 0
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
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 gambar2
For Pb = 0 To .Height - 1
For Pc = 0 To .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 vB > 255 Then vB = 255
If vH > 255 Then vH = 255
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
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 gambar2
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
rata = (vM + vH + vB) / 3
If (rata < 128) Then
vH = 0
vM = 0
vB = 0
Else
vM = 255
vH = 255
vB = 255
End If
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End With
End Sub
Private Sub DToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DToolStripMenuItem.Click
Pic1.Image = Pic2.Image
End Sub
Private Sub ToolStripMenuItem180_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar3 As Bitmap = New Bitmap(Pic1.Image)
With gambar2
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(.Width - 1 - Pc, .Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar3
Pic2.Refresh()
Next
End With
gambar3 = gambar3
End Sub
Private Sub DERAJATToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DERAJATToolStripMenuItem.Click
Dim gambar2 = New Bitmap(Pic1.Image)
gambar2 = New Bitmap(Pic1.Image)
Pic1.Image = gambar2
gambar2.RotateFlip(RotateFlipType.Rotate90FlipNone)
Pic1.Image = gambar2
End Sub
Private Sub DERAJATToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DERAJATToolStripMenuItem1.Click
Dim Pb, Pc As Integer
Dim vM, vH, vB As Double
Dim gambar3 As Bitmap = New Bitmap(Pic1.Image)
With gambar2
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
gambar2.SetPixel(.Width - 1 - Pc, .Height - 1 - Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar3
Pic2.Refresh()
Next
End With
gambar3 = gambar3
End Sub
Private Sub CERMINToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CERMINToolStripMenuItem.Click
Dim gambar3 = New Bitmap(Pic1.Image)
gambar3 = New Bitmap(Pic1.Image)
Pic1.Image = gambar3
gambar3.RotateFlip(RotateFlipType.RotateNoneFlipX)
Pic2.Image = gambar3
End Sub
Private Sub REDToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles REDToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar2
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
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 0
vM = 255
vB = 0
Else
vM = 0
vH = 0
vB = 0
End If
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End With
gambar2 = gambar2
End Sub
Private Sub GREENToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GREENToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar2
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
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 255
vM = 0
vB = 0
Else
vM = 0
vH = 0
vB = 0
End If
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End With
gambar2 = gambar2
End Sub
Private Sub BLUEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BLUEToolStripMenuItem.Click
Dim Pb, Pc As Integer
Dim rata, vM, vH, vB As Double
With gambar2
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 + 10
rata = (vM + vH + vB) / 3
If (rata >= 255) Then
vH = 0
vM = 0
vB = 255
Else
vM = 0
vH = 0
vB = 0
End If
gambar2.SetPixel(Pc, Pb, Color.FromArgb(vM, vH, vB))
Next
Pic2.Image = gambar2
Pic2.Refresh()
Next
End With
gambar2 = gambar2
End Sub
Private Sub OFD_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFD.FileOk
End Sub
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
End Sub
End Class
hasil program
Komentar
Posting Komentar