聲明這是無法隱式轉換類型「爲System.Drawing.Image」到「System.Drawing.Bitmap'`
private Bitmap img1 = null;
private Bitmap img2 = null;
圖像將從中選擇打開文件對話框後推杆的位圖。
所選圖像被放置在一個數組中。
imgName = openFD.FileNames;
然後按鈕1顯示這些圖像。
pictureBox1.Image = Image.FromFile(imgName[0]);
pictureBox2.Image = Image.FromFile(imgName[1]);
我更換Button1的代碼與此
img1 = Image.FromFile(imgName[0]);
img2 = Image.FromFile(imgName[1]);
但出現錯誤
無法隱式轉換類型 '爲System.Drawing.Image' 到 'System.Drawing.Bitmap'
我會嘗試將代碼更改爲img1 = Bitmap.FromFile(imgName[0]);
。但仍然有相同的錯誤。
任何建議如何糾正或做到這一點的權利?
雖然位圖始終被視爲圖像,但圖像不一定是位圖。它爲未來的其他類型的圖像提供支持。因此,您不應該嘗試強制映像成爲位圖。 – 2012-01-14 08:25:41