📄 form1.vb
字号:
#End Region
Dim bmap As Bitmap
Private Sub FileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileOpen.Click
OpenFileDialog1.Filter = "Images|*.GIF;*.TIF;*.JPG"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = "" Then Exit Sub
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
PictureBox1.Width = PictureBox1.Height * PictureBox1.Image.Width / PictureBox1.Image.Height
Me.Text = "(" & PictureBox1.Image.Width.ToString & ", " & PictureBox1.Image.Height.ToString & ")"
End Sub
Private Sub ProcessEmboss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessEmboss.Click
bmap = New Bitmap(PictureBox1.Image)
PictureBox1.Image = bmap
Dim tempbmp As New Bitmap(PictureBox1.Image)
Dim i, j As Integer
Dim DispX As Integer = 1, DispY As Integer = 1
Dim red, green, blue As Integer
With tempbmp
For i = 0 To .Height - 2
For j = 0 To .Width - 2
Dim pixel1, pixel2 As System.Drawing.Color
pixel1 = .GetPixel(j, i)
pixel2 = .GetPixel(j + DispX, i + DispY)
red = Math.Min(Math.Abs(CInt(pixel1.R) - CInt(pixel2.R)) + 128, 255)
green = Math.Min(Math.Abs(CInt(pixel1.G) - CInt(pixel2.G)) + 128, 255)
blue = Math.Min(Math.Abs(CInt(pixel1.B) - CInt(pixel2.B)) + 128, 255)
bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))
Next
If i Mod 10 = 0 Then
PictureBox1.Invalidate()
PictureBox1.Refresh()
Me.Text = Int(100 * i / (PictureBox1.Image.Height - 2)).ToString & "%"
End If
Next
End With
PictureBox1.Refresh()
Me.Text = "Done embossing image"
End Sub
Private Sub ProcessSharpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessSharpen.Click
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 i, j As Integer
With tempbmp
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
red = CInt(.GetPixel(j, i).R) + 0.5 * CInt((.GetPixel(j, i).R) - CInt(.GetPixel(j - DX, i - DY).R))
green = CInt(.GetPixel(j, i).G) + 0.7 * CInt((.GetPixel(j, i).G) - CInt(.GetPixel(j - DX, i - DY).G))
blue = CInt(.GetPixel(j, i).B) + 0.5 * CInt((.GetPixel(j, i).B - CInt(.GetPixel(j - DX, i - DY).B)))
red = Math.Min(Math.Max(red, 0), 255)
green = Math.Min(Math.Max(green, 0), 255)
blue = Math.Min(Math.Max(blue, 0), 255)
bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))
Next
If i Mod 10 = 0 Then
PictureBox1.Invalidate()
Me.Text = Int(100 * i / (PictureBox1.Image.Height - 2)).ToString & "%"
PictureBox1.Refresh()
End If
Next
End With
PictureBox1.Refresh()
Me.Text = "Done sharpening image"
End Sub
Private Sub ProcessSmooth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessSmooth.Click
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 i, j As Integer
With tempbmp
For i = DX To .Height - DX - 1
For j = DY To .Width - DY - 1
red = CInt((CInt(.GetPixel(j - 1, i - 1).R) + _
CInt(.GetPixel(j - 1, i).R) + _
CInt(.GetPixel(j - 1, i + 1).R) + _
CInt(.GetPixel(j, i - 1).R) + _
CInt(.GetPixel(j, i).R) + _
CInt(.GetPixel(j, i + 1).R) + _
CInt(.GetPixel(j + 1, i - 1).R) + _
CInt(.GetPixel(j + 1, i).R) + _
CInt(.GetPixel(j + 1, i + 1).R)) / 9)
green = CInt((CInt(.GetPixel(j - 1, i - 1).G) + _
CInt(.GetPixel(j - 1, i).G) + _
CInt(.GetPixel(j - 1, i + 1).G) + _
CInt(.GetPixel(j, i - 1).G) + _
CInt(.GetPixel(j, i).G) + _
CInt(.GetPixel(j, i + 1).G) + _
CInt(.GetPixel(j + 1, i - 1).G) + _
CInt(.GetPixel(j + 1, i).G) + _
CInt(.GetPixel(j + 1, i + 1).G)) / 9)
blue = CInt((CInt(.GetPixel(j - 1, i - 1).B) + _
CInt(.GetPixel(j - 1, i).B) + _
CInt(.GetPixel(j - 1, i + 1).B) + _
CInt(.GetPixel(j, i - 1).B) + _
CInt(.GetPixel(j, i).B) + _
CInt(.GetPixel(j, i + 1).B) + _
CInt(.GetPixel(j + 1, i - 1).B) + _
CInt(.GetPixel(j + 1, i).B) + _
CInt(.GetPixel(j + 1, i + 1).B)) / 9)
red = Math.Min(Math.Max(red, 0), 255)
green = Math.Min(Math.Max(green, 0), 255)
blue = Math.Min(Math.Max(blue, 0), 255)
bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))
Next
If i Mod 10 = 0 Then
PictureBox1.Invalidate()
PictureBox1.Refresh()
Me.Text = Int(100 * i / (PictureBox1.Image.Height - 2)).ToString & "%"
End If
Next
End With
PictureBox1.Refresh()
Me.Text = "Done smoothing image"
End Sub
Private Sub ViewNormal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewNormal.Click
PictureBox1.Width = PictureBox1.Image.Width
PictureBox1.Height = PictureBox1.Image.Height
End Sub
Private Sub ViewZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewZoomOut.Click
PictureBox1.Width = PictureBox1.Width / 2
PictureBox1.Height = PictureBox1.Height / 2
End Sub
Private Sub ViewZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewZoomIn.Click
PictureBox1.Width = PictureBox1.Width * 2
PictureBox1.Height = PictureBox1.Height * 2
End Sub
Private Sub ProcessDiffuse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessDiffuse.Click
bmap = New Bitmap(PictureBox1.Image)
PictureBox1.Image = bmap
Dim tempbmp As New Bitmap(PictureBox1.Image)
Dim i As Integer, j As Integer
Dim DX As Integer
Dim DY As Integer
Dim red As Integer, green As Integer, blue As Integer
With tempbmp
For i = 3 To .Height - 3
For j = 3 To .Width - 3
DX = Rnd() * 4 - 2
DY = Rnd() * 4 - 2
red = .GetPixel(j + DX, i + DY).R
green = .GetPixel(j + DX, i + DY).G
blue = .GetPixel(j + DX, i + DY).B
bmap.SetPixel(j, i, Color.FromArgb(red, green, blue))
Next
Me.Text = Int(100 * i / (.Height - 2)).ToString & "%"
If i Mod 10 = 0 Then
PictureBox1.Invalidate()
PictureBox1.Refresh()
Me.Text = Int(100 * i / (PictureBox1.Image.Height - 2)).ToString & "%"
End If
Next
End With
PictureBox1.Refresh()
Me.Text = "Done diffusing image"
End Sub
Private Sub RotateLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RotateLeft.Click
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
PictureBox1.Width = PictureBox1.Height * PictureBox1.Image.Width / PictureBox1.Image.Height
End Sub
Private Sub RotateRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RotateRight.Click
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
PictureBox1.Width = PictureBox1.Height * PictureBox1.Image.Width / PictureBox1.Image.Height
End Sub
Private Sub FlipH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlipH.Click
PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
PictureBox1.Refresh()
End Sub
Private Sub FlipV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlipV.Click
PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY)
PictureBox1.Refresh()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -