Try Dim fo As New OpenFileDialog fo.Filter = "BitMap Files|*.bmp" fo.FilterIndex = 1 fo.ShowDialog() If (fo.FileName.ToLower().EndsWith(".bmp")) Then Dim image1 As Bitmap = New Bitmap(fo.FileName, True) Dim x, y As Integer For x = 0 To image1.Width - 1 For y = 0 To image1.Height - 1 Dim pixelColor As Color = image1.GetPixel(x, y) Dim newColor As Color = _ Color.FromArgb(pixelColor.R, 0, 0) image1.SetPixel(x, y, newColor) Next Next PictureBox1.Image = image1 Me.Width = image1.Width + 60 PictureBox1.Width = image1.Width PictureBox1.Location = New Point(10, 50) PictureBox1.Height = image1.Height Me.Height = image1.Height + 50 Else : MsgBox("That is not a BitMap file. Bitmap files end with "".bmp"".") End If Catch ex As ArgumentException MessageBox.Show(ex.ToString()) End Try
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim fo As New OpenFileDialog fo.Filter = "BitMap Files|*.bmp" fo.FilterIndex = 1 fo.ShowDialog() If (fo.FileName.ToLower().EndsWith(".bmp")) Then Dim image1 As Bitmap = New Bitmap(fo.FileName, True) Dim x, y As Integer For x = 0 To image1.Width - 1 For y = 0 To image1.Height - 1 Dim pixelColor As Color = image1.GetPixel(x, y) Dim newColor As Color = _ Color.FromArgb(pixelColor.R, 0, 0) image1.SetPixel(x, y, newColor) Next Next PictureBox1.Image = image1 Me.Width = image1.Width + 60 PictureBox1.Width = image1.Width PictureBox1.Location = New Point(10, 50) PictureBox1.Height = image1.Height Me.Height = image1.Height + 50 Else : MsgBox("That is not a BitMap file. Bitmap files end with "".bmp"".") End If Catch ex As ArgumentException MessageBox.Show(ex.ToString()) End Try End Sub End Class