2011-12-28 63 views
3

Accord.NET PointsMarker.cs似乎支持PixelFormat Format32bppArgb。 爲什麼會捕獲一個UnsupportedImageFormatException?如何修復UnsupportedImageFormatException PixelFormat Format32bppArgb?

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

回答

4

雖然Format32bppArgb似乎在Accord.NET PointsMarker.cs源我可以修復它得到支持通過添加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; 
} 
+1

SO需要署名。 http://stackoverflow.com/a/2016509/17034 – 2011-12-28 22:11:50

+0

對不起。我的錯。我通常這樣做。 – jacknad 2011-12-29 21:31:36

-2

解決此問題的另一種方法是將圖像保存爲System.Drawing.Image(例如xxx.jpg etc)。然後將圖像作爲圖像讀取並將其轉換爲位圖。
它爲我工作。