jacknad
jacknad

Reputation: 13739

How to repair UnsupportedImageFormatException PixelFormat Format32bppArgb?

Accord.NET PointsMarker.cs seems to support PixelFormat Format32bppArgb. Why does this catch an 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);
    }
}

The Console.WriteLine is

UnsupportedImageFormatException PixelFormat Format32bppArgb UnsupportedImageFormatException PixelFormat Format32bppArgb

Upvotes: 3

Views: 2227

Answers (2)

Eranjene Sandun
Eranjene Sandun

Reputation: 1

Another way to get around this problem is to save the image just as a System.Drawing.Image (For example xxx.jpg etc). and then read the image back as an image and convert it to a bitmap.
It worked for me.

Upvotes: -2

jacknad
jacknad

Reputation: 13739

Although Format32bppArgb seems to be supported in the Accord.NET PointsMarker.cs source I was able to repair it by adding 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;
}

Upvotes: 4

Related Questions