0% found this document useful (0 votes)
47 views5 pages

Form1 Image Bitmap Bitmap Bitmap Bitmap Color

This document contains the code for a Windows Forms application that allows a user to open an image, apply various grayscale and color channel filters, and display the results. The key aspects are: 1. It defines classes and variables to store image data and pixel color values. 2. The Browse_Click event handler opens an image and scales it to fit the picture box, storing the pixel data. 3. Radio button check changed events apply different grayscale and single channel color filters and display the results.

Uploaded by

bayu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Form1 Image Bitmap Bitmap Bitmap Bitmap Color

This document contains the code for a Windows Forms application that allows a user to open an image, apply various grayscale and color channel filters, and display the results. The key aspects are: 1. It defines classes and variables to store image data and pixel color values. 2. The Browse_Click event handler opens an image and scales it to fit the picture box, storing the pixel data. 3. Radio button check changed events apply different grayscale and single channel color filters and display the results.

Uploaded by

bayu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Imports System.Drawing.

Imaging
Public Class Form1
Dim PicBoxHeight As Integer
Dim PicBoxWidth As Integer
Dim TempImage As Image
Dim ImageHeight As Integer
Dim ImageWidth As Integer
Dim ImageOri As Bitmap
Dim scale_factor As Single
Dim Image1 As Bitmap
Dim Image2 As Bitmap
Dim Image3 As Bitmap
Dim ColArray(,) As Color
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 Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Browse.Click
If PictureBox1.Image Is Nothing Then
PictureBox1.Enabled = False
Else
PictureBox1.Enabled = True
End If
Try
PictureBox1.Height = 535
PictureBox1.Width = 354
OpenFileDialog1.Title = "Open Picture"
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Format Gambar|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.gif"
OpenFileDialog1.ShowDialog()
PictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
Resolution.Text = "Resolution : " & PictureBox1.Image.Width & "x" &
PictureBox1.Image.Height
Location.Text = OpenFileDialog1.FileName
PictureBox1.Enabled = True
ImageOri = New Bitmap(PictureBox1.Image)
PicBoxHeight = PictureBox1.Height
PicBoxWidth = PictureBox1.Width
TempImage = PictureBox1.Image
ImageHeight = TempImage.Height
ImageWidth = TempImage.Width
If ImageHeight > PicBoxHeight Then
scale_factor = CSng(PicBoxHeight / ImageHeight)
End If
If (ImageWidth * scale_factor) > PicBoxWidth Then
scale_factor = CSng(PicBoxWidth / ImageWidth)
End If
PictureBox1.Image = TempImage
Dim bm_source As New Bitmap(PictureBox1.Image)
Dim bm_dest As New Bitmap( _
CInt(bm_source.Width * scale_factor), _
CInt(bm_source.Height * scale_factor))
Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
gr_dest.DrawImage(bm_source, 0, 0, _
bm_dest.Width + 1, _

bm_dest.Height + 1)
PictureBox1.Image = bm_dest
PictureBox1.Height = PictureBox1.Image.Height
PictureBox1.Width = PictureBox1.Image.Width
Image1 = New Bitmap(PictureBox1.Image)
Image2 = New Bitmap(PictureBox1.Image)
Image3 = New Bitmap(PictureBox1.Image)
ReDim ColArray(PictureBox1.Image.Width - 1, PictureBox1.Image.Height - 1)
ProgressBar1.Visible = True
ProgressBar1.Maximum = (PictureBox1.Image.Width - 1) * (PictureBox1.Image.Height - 1)
ProgressBar1.Step = 1
For x = 0 To PictureBox1.Image.Width - 1
For y = 0 To PictureBox1.Image.Height - 1
ColArray(x, y) = Image1.GetPixel(x, y)
ProgressBar1.PerformStep()
Next y
Next x
ProgressBar1.Visible = False
ProgressBar1.Value = 0
Catch ex As Exception
If PictureBox1.Image Is Nothing Then
PictureBox1.Enabled = False
Else
PictureBox1.Height = PictureBox1.Image.Height
PictureBox1.Width = PictureBox1.Image.Width
End If
End Try
End Sub
Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Copy.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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
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

End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.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(ByVal sender As System.Object, ByVal e As
System.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 RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.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(ByVal sender As System.Object, ByVal e As
System.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(ByVal sender As System.Object, ByVal e As
System.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 RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As
System.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
End Class

You might also like