You are on page 1of 5

Imports System.Drawing.

Imaging
Public Class Form1
Dim w As New Integer
Dim h As New Integer
Dim x As Integer
Dim y As Integer
Dim r, g, b, gr As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim open As New OpenFileDialog()
open.Filter = "Image Files(*.png; *.jpg; *.bmp|*.png; *.jpg; *.bmp"
If open.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fileName As String = System.IO.Path.GetFullPath(open.FileName)
PictureBox1.Image = New Bitmap(open.FileName)
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
For Me.x = 0 To w - 1
For Me.y = 0 To w - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
bmp.SetPixel(x, y, pixelcolor)
Next y
Next x
PictureBox2.Image = bmp
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton1.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton1.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
r = pixelcolor.R
bmp.SetPixel(x, y, Color.FromArgb(r, 0, 0))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton2.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)

PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton2.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
g = pixelcolor.G
bmp.SetPixel(x, y, Color.FromArgb(0, g, 0))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton3.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton3.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
b = pixelcolor.B
bmp.SetPixel(x, y, Color.FromArgb(0, 0, b))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub HScrollBar1_Scroll(sender As Object, e As EventArgs) Handles HScrollBar1.Scroll
Dim brightness As Single = CSng(HScrollBar1.Value / 50)
Dim contrast As Single = 1.0F
Dim adjustedBrightness As Single = brightness - 1.0F
Dim image_attr As New ImageAttributes
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
{
New Single() {contrast, 0.0, 0.0, 0.0, 0.0},
New Single() {0.0, contrast, 0.0, 0.0, 0.0},
New Single() {0.0, 0.0, contrast, 0.0, 0.0},
New Single() {0.0, 0.0, 0.0, 1.0, 0.0},
New Single() {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0.0, 1.0}})
Dim rect As Rectangle =
Rectangle.Round(PictureBox2.Image.GetBounds(GraphicsUnit.Pixel))
Dim w As Integer = PictureBox2.ClientSize.Width
Dim h As Integer = PictureBox2.ClientSize.Height
Dim img As New Bitmap(w, h)
Dim gr As Graphics = Graphics.FromImage(img)
image_attr.SetColorMatrix(cm)
gr.DrawImage(PictureBox2.Image, rect, 0, 0, w,
h, GraphicsUnit.Pixel, image_attr)

PictureBox4.Image = img
End Sub
Private Sub RadioButton7_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton7.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton7.Checked = True Then
For Me.x = 0 To w - 1
For Me.y = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(y, x)
bmp.SetPixel(y, x, Color.FromArgb(255 - pixelcolor.R, 255 - pixelcolor.G, 255 pixelcolor.B))
Next y
Next x
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton8_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton8.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton8.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(y, x)
r = pixelcolor.R
g = pixelcolor.G
b = pixelcolor.B
gr = Int((r + g + b) / 3)
bmp.SetPixel(y, x, Color.FromArgb(gr, gr, gr))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton4.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton4.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)

g = pixelcolor.G
b = pixelcolor.B
bmp.SetPixel(x, y, Color.FromArgb(0, g, b))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton5.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton5.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
r = pixelcolor.R
b = pixelcolor.B
bmp.SetPixel(x, y, Color.FromArgb(r, 0, b))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub RadioButton6_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton6.CheckedChanged
w = PictureBox1.ClientSize.Width
h = PictureBox1.ClientSize.Height
Dim bmp As New Bitmap(w, h)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
If RadioButton6.Checked = True Then
For Me.y = 0 To w - 1
For Me.x = 0 To h - 1
Dim pixelcolor As Color = bmp.GetPixel(x, y)
g = pixelcolor.G
r = pixelcolor.R
bmp.SetPixel(x, y, Color.FromArgb(r, g, 0))
Next x
Next y
End If
PictureBox3.Image = bmp
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
PictureBox1.Image = Nothing
PictureBox2.Image = Nothing
PictureBox3.Image = Nothing
PictureBox4.Image = Nothing
RadioButton1.Checked = Nothing

RadioButton2.Checked = Nothing
RadioButton3.Checked = Nothing
RadioButton4.Checked = Nothing
RadioButton5.Checked = Nothing
RadioButton6.Checked = Nothing
RadioButton7.Checked = Nothing
RadioButton8.Checked = Nothing
HScrollBar1.Value = Nothing
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
End Class

You might also like