caranya :
- Public Class Form1
- Dim bmap As Bitmap
- Private Sub Openbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Openbtn.Click
- OpenFileDialog1.InitialDirectory = "c:\"
- OpenFileDialog1.Title = "Open Images"
- OpenFileDialog1.Filter = "Gambar|*.bmp;*.gif;*.jpg;*.png"
- If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
- PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
- Exit Sub
- End If
- End Sub
- Private Sub Grayscale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Grayscale.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- Dim PICTURE As New Bitmap(PictureBox1.Image)
- Dim X, Y, warna As Integer
- For X = 0 To PICTURE.Width - 1
- For Y = 0 To PICTURE.Height - 1
- Dim p = PICTURE.GetPixel(X, Y)
- warna = CInt(p.R * 0.3 + p.G * 0.59 + p.B * 0.11)
- PICTURE.SetPixel(X, Y, Color.FromArgb(warna, warna, warna))
- PictureBox1.Image = PICTURE
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- If Y Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- End Sub
- Private Sub Savebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Savebtn.Click
- SaveFileDialog1.FileName = "Save Images"
- SaveFileDialog1.Filter = "Gambar|*.bmp;*.gif;*.jpg;*.png"
- If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
- PictureBox1.Image.Save(SaveFileDialog1.FileName)
- End If
- End Sub
- Private Sub Binerbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Binerbtn.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- bmap = New Bitmap(PictureBox1.Image)
- PictureBox1.Image = bmap
- Dim tempbmp As New Bitmap(PictureBox1.Image)
- Dim DX As Integer
- Dim DY As Integer
- Dim Red, Green, Blue, Grey As Integer
- Dim X, Y As Integer
- With tempbmp
- For X = DX To .Height - DX - 1
- For Y = DY To .Width - DY - 1
- Red = CInt(.GetPixel(Y, X).R)
- Green = CInt(.GetPixel(Y, X).G)
- Blue = CInt(.GetPixel(Y, X).B)
- Grey = (Red + Green + Blue) / 3
- 'proses perubahan ke biner (hitam putih)
- Dim clr As Color = bmap.GetPixel(Y, X)
- If (Grey < 128) Then
- Red = 0
- Green = 0
- Blue = 0
- Else
- Red = 255
- Blue = 255
- Green = 255
- End If
- bmap.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- End With
- End Sub
- Private Sub mbitbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mbitbtn.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- bmap = New Bitmap(PictureBox1.Image)
- PictureBox1.Image = bmap
- Dim tempbmp As New Bitmap(PictureBox1.Image)
- Dim DX As Integer = 1
- Dim DY As Integer = 1
- Dim Red As Integer, Green As Integer, Blue As Integer, Grey As Integer
- Dim X, Y As Integer
- Dim m As Integer = 2
- Dim Xth As Double
- With tempbmp
- For X = DX To .Height - DX - 1
- For Y = DY To .Width - DY - 1
- Red = CInt(.GetPixel(Y, X).R)
- Green = CInt(.GetPixel(Y, X).G)
- Blue = CInt(.GetPixel(Y, X).B)
- Grey = (Red + Green + Blue) / 3
- Xth = (2 ^ m) * Int(Grey / 2 ^ m)
- If (Xth > 256) Then
- Red = 255
- Green = 255
- Blue = 255
- Else
- Red = Xth
- Green = Xth
- Blue = Xth
- End If
- bmap.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- End With
- End Sub
- Private Sub Brightbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Brightbtn.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- bmap = New Bitmap(PictureBox1.Image)
- PictureBox1.Image = bmap
- Dim tempbmp As New Bitmap(PictureBox1.Image)
- Dim DX As Integer = 1
- Dim DY As Integer = 1
- Dim Red As Integer, Green As Integer, Blue As Integer
- Dim X, Y As Integer
- Dim tb As Integer
- tb = 75
- With tempbmp
- For X = DX To .Height - DX - 1
- For Y = DY To .Width - DY - 1
- Red = CInt(.GetPixel(Y, X).R)
- Green = CInt(.GetPixel(Y, X).G)
- Blue = CInt(.GetPixel(Y, X).B)
- 'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
- Red = Red + tb
- Green = Green + tb
- Blue = Blue + tb
- If (Red > 255) Then
- Red = 255
- End If
- If (Blue > 255) Then
- Blue = 255
- End If
- If (Green > 255) Then
- Green = 255
- End If
- bmap.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- End With
- End Sub
- Private Sub Contrastbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Contrastbtn.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- bmap = New Bitmap(PictureBox1.Image)
- PictureBox1.Image = bmap
- Dim tempbmp As New Bitmap(PictureBox1.Image)
- Dim DX As Integer = 1
- Dim DY As Integer = 1
- Dim Red, Green, Blue As Integer
- Dim X, Y As Integer
- Dim tc As Integer
- tc = 5
- With tempbmp
- For X = DX To .Height - DX - 1
- For Y = DY To .Width - DY - 1
- Red = CInt(.GetPixel(Y, X).R)
- Green = CInt(.GetPixel(Y, X).G)
- Blue = CInt(.GetPixel(Y, X).B)
- 'Grey = (Red + Green + Blue) / 3 'konversi warna pada pixel Y,X ke grey
- Red = Red * tc
- Blue = Blue * tc
- Green = Green * tc
- If (Red > 255) Then
- Red = 255
- End If
- If (Blue > 255) Then
- Blue = 255
- End If
- If (Green > 255) Then
- Green = 255
- End If
- bmap.SetPixel(Y, X, Color.FromArgb(Red, Green, Blue))
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- End With
- End Sub
- Private Sub Inversibtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Inversibtn.Click
- If PictureBox1.Image Is Nothing Then
- MsgBox("WARNING : Tidak ada gambar untuk di konversi!")
- Exit Sub
- End If
- bmap = New Bitmap(PictureBox1.Image)
- PictureBox1.Image = bmap
- Dim tempbmp As New Bitmap(PictureBox1.Image)
- Dim DX As Integer
- Dim DY As Integer
- Dim X, Y As Integer
- With tempbmp
- For X = DX To .Height - DX - 1
- For Y = DY To .Width - DY - 1
- Dim clr As Color = bmap.GetPixel(Y, X)
- 'inversi 8 bit = 255-x
- clr = Color.FromArgb(255, 255 - clr.R, 255 - clr.G, 255 - clr.B)
- bmap.SetPixel(Y, X, clr)
- Next
- If X Mod 10 = 0 Then
- PictureBox1.Invalidate()
- PictureBox1.Refresh()
- End If
- Next
- End With
- End Sub
- Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
- End
- End Sub
- End Class
Tidak ada komentar:
Posting Komentar