如何修复UnsupportedImageFormatException PixelFormat Format32bppArgb?

3
Accord.NET似乎支持PixelFormat Format32bppArgb。为什么会出现UnsupportedImageFormatException错误?PointsMarker.cs
private void Harris()
{
    try
    {
        img1 = new Bitmap(pictureBox1A.Image);
        img2 = new Bitmap(pictureBox1B.Image);
        var harris = new HarrisCornersDetector(0.04f, 1000f);
        harrisPoints1 = harris.ProcessImage(img1).ToArray();
        harrisPoints2 = harris.ProcessImage(img2).ToArray();
        // Show the marked points in the original images
        var img1mark = new PointsMarker(harrisPoints1).Apply(img1);
        var img2mark = new PointsMarker(harrisPoints2).Apply(img2);
        // Concatenate the two images together in a single image
        var concatenate = new Concatenate(img1mark);
        pictureBox.Image = concatenate.Apply(img2mark);
    }
    catch (UnsupportedImageFormatException)
    {
        const string S = "UnsupportedImageFormatException PixelFormat ";
        Console.WriteLine(S + img1.PixelFormat);
        Console.WriteLine(S + img2.PixelFormat);
    }
}

Console.WriteLine是

UnsupportedImageFormatException像素格式为Format32bppArgb的格式不支持 UnsupportedImageFormatException像素格式为Format32bppArgb的格式不支持

2个回答

4

虽然 Accord.NET 的 PointsMarker.cs 源代码中似乎支持 Format32bppArgb,但我通过添加此内容进行修复:

// Convert to Format24bppRgb
private static Bitmap Get24bppRgb(Image image)
{
    var bitmap = new Bitmap(image);
    var bitmap24 = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format24bppRgb);
    using (var gr = Graphics.FromImage(bitmap24))
    {
        gr.DrawImage(bitmap, new Rectangle(0, 0, bitmap24.Width, bitmap24.Height));
    }
    return bitmap24;
}

-2
另一种解决此问题的方法是将图像仅保存为System.Drawing.Image(例如xxx.jpg等),然后将其作为图像读回并将其转换为位图。
这对我有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接