在 VB.NET 中使用 AForge.NET 反转图像

Invert image with AForge.NET in VB.NET

我正在做一个 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

它说没有错误。但是当我 运行 这个我得到一个错误说 -

An unhandled exception of type 'AForge.Imaging.UnsupportedImageFormatException' occurred in AForge.Imaging.dll

。 See Screenshot

问题出在像素上 format.I 我正在发布工作代码,希望有一天它能帮助到其他人-

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