我正在开发一个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
答案 0 :(得分:0)
问题在于像素格式。我发布了工作代码,希望有一天它可以帮助别人 -
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