【问题标题】:How to repair UnsupportedImageFormatException PixelFormat Format32bppArgb?如何修复 UnsupportedImageFormatException PixelFormat Format32bppArgb?
【发布时间】:2012-10-31 00:28:53
【问题描述】:

Accord.NET PointsMarker.cs 似乎支持 PixelFormat Format32bppArgb。 为什么这会捕获 UnsupportedImageFormatException?

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 PixelFormat Format32bppArgb UnsupportedImageFormatException PixelFormat Format32bppArgb

【问题讨论】:

    标签: c# image bitmap pixelformat


    【解决方案1】:

    虽然 Accord.NET PointsMarker.cs 源似乎支持 Format32bppArgb,但我可以通过添加 this 来修复它:

    // 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 etc)。然后将图像作为图像读回并将其转换为位图。
      它对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-07
        • 1970-01-01
        相关资源
        最近更新 更多