|
Private imageBitmap As Bitmap
Private Sub MenuItem2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim imageTemp As Bitmap
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
If (Not imageBitmap Is Nothing) Then
imageBitmap.Dispose()
End If
imageTemp = New Bitmap(OpenFileDialog1.FileName)
imageBitmap = New Bitmap(imageTemp, PictureBox1.Width, _
PictureBox1.Height)
imageTemp.Dispose()
PictureBox1.Invalidate()
End If
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem3.Click
Dim Schwarzweiß As Integer
Dim colo, newcolor As Color
Dim x, y As Integer
If imageBitmap Is Nothing Then
Exit Sub
End If
Me.Cursor.Current = Windows.Forms.Cursors.WaitCursor
For x = 0 To PictureBox1.Width - 1
For y = 0 To PictureBox1.Height - 1
colo = imageBitmap.GetPixel(x, y)
Schwarzweiß = CInt((CType(colo.R, Integer) + _
CType(colo.G, Integer) + _
CType(colo.B, Integer)) / 3)
newcolor = Color.FromArgb(colo.A, Schwarzweiß, _
Schwarzweiß, Schwarzweiß)
imageBitmap.SetPixel(x, y, newcolor)
Next
PictureBox1.Invalidate()
PictureBox1.Refresh()
Next
Me.Cursor.Current = Windows.Forms.Cursors.Default
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MenuItem4.Click
If imageBitmap Is Nothing Then
Exit Sub
End If
SaveFileDialog1.Filter = "Bitmap (*.bmp)|*.bmp"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
If (SaveFileDialog1.FileName.EndsWith("bmp")) Then
imageBitmap.Save(SaveFileDialog1.FileName, _
Imaging.ImageFormat.Bmp)
End If
End If
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PictureBox1.Paint
If Not imageBitmap Is Nothing Then
e.Graphics.DrawImage(imageBitmap, 0, 0)
End If
End Sub
|
|