【问题标题】:Invert image with AForge.NET in VB.NET在 VB.NET 中使用 AForge.NET 反转图像
【发布时间】:2017-01-28 05:22:14
【问题描述】:
我正在开发一个 OMR 项目,我必须使用 VB.NET 使用 AForge.NET 反转图像。
我正在使用此代码 -
Private Sub Load_Butt_Click(sender As Object, e As EventArgs) Handles Load_Butt.Click
' load image
Dim image As Bitmap = AForge.Imaging.Image.FromFile("c://test.bmp")
' create invert filter
Dim filter As New Invert()
Dim inv_img As Bitmap
' apply the invert filter
inv_img = filter.Apply(image)
PictureBox1.Image = inv_img
End Sub
它说没有错误。但是当我运行它时,我收到一条错误消息 -
未处理的类型异常
'AForge.Imaging.UnsupportedImageFormatException' 发生在
AForge.Imaging.dll
。
See Screenshot
【问题讨论】:
标签:
vb.net
image-processing
aforge
optical-mark-recognition
【解决方案1】:
问题出在像素格式上。我正在发布工作代码,希望有一天它可以帮助其他人-
Public image As Bitmap = AForge.Imaging.Image.FromFile("c://test.bmp")
Public inv_img As Bitmap
Public Sub ApplyFilter(filter As IFilter)
' apply filter
inv_img = filter.Apply(image)
' display image
PictureBox1.Image = inv_img
End Sub
Public Sub Load_Butt_Click(sender As Object, e As EventArgs) Handles Load_Butt.Click
' check pixel format
If (image.PixelFormat = PixelFormat.Format16bppGrayScale) OrElse (Bitmap.GetPixelFormatSize(image.PixelFormat) > 32) Then
MessageBox.Show("The demo application supports only color images.", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
' free image
image.Dispose()
image = Nothing
Else
' make sure the image has 24 bpp format
If image.PixelFormat <> PixelFormat.Format24bppRgb Then
Dim temp As Bitmap = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb)
image.Dispose()
image = temp
End If
End If
ApplyFilter(New Invert())
End Sub