【发布时间】:2015-07-30 19:57:41
【问题描述】:
我是 Visual Basic 的新手,过去我在 matlab 中做过图像处理。但目前需要 Visual Basic 中的图像处理。好的,我已经能够显示图像并阅读转换为灰度的内容。但是,我的图像是 jpeg 格式,并且在几个灰度转换器教程中,我一直运行到仅 bmp 图像的位图函数,并且我的代码在尝试处理 JPEG 格式时不断产生错误。我如何阅读 jpeg 并执行灰度操作。这是代码。
Public Class Form1
Private Sub showButton_Click(sender As System.Object, e As System.EventArgs) Handles showButton.Click
' Show the Open File dialog. If the user clicks OK, load the
' picture that the user chose.
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.Load(OpenFileDialog1.FileName)
End If
End Sub
Private Sub GrayImageButton_Click(sender As System.Object, e As System.EventArgs) Handles GrayImageButton.Click
Dim bm As New jpeg(PictureBox1.Image)
Dim X As Integer
Dim Y As Integer
Dim clr As Integer
For X = 0 To bm.Width - 1
For Y = 0 To bm.Height - 1
clr = (CInt(bm.GetPixel(X, Y).R) + _
bm.GetPixel(X, Y).G + _
bm.GetPixel(X, Y).B) \ 3
bm.SetPixel(X, Y, Color.FromArgb(clr, clr, clr))
Next Y
Next X
PictureBox1.Image = bm
End Sub
我收到的错误是
错误 1:“WindowsApplication1.jpeg”类型的值无法转换为“System.Drawing.Image”。
当我使用 bmp 图像实现此功能时,它可以完美运行,但不适用于 jpeg。对于此问题的任何帮助,我将不胜感激。谢谢
【问题讨论】: