我正在嘗試做一種可以將 Emgu.Cv.Mat 影像轉換為 System.Drawing.Bitmap 影像的方法。
public Bitmap convertCvToBitmap(Mat img)
{
byte[] temp_img = this.convertCvToImage(img);
Bitmap mp;
using (var ms = new MemoryStream(temp_img))
{
mp = new Bitmap(ms);
}
return mp;
}
首先我將 Emgu.Cv.Mat 影像轉換為 byte[] 影像,然后我將此 byte[] 影像轉換為 System.Drawing.Bitmap 影像。
此方法適用于桌面,但不適用于 Xamarin Android 應用程式,我收到此錯誤:“ System.PlatformNotSupportedException: 'Operation is not supported on this platform.'”。
我知道它來自這行代碼:(mp = new Bitmap(ms);我在使用之前檢查過Console.WriteLine)
誰能知道這個問題,或者是否有其他路徑可以將 Emgu.Cv.Mat 影像轉換為 System.Drawing.Bitmap 影像?
謝謝!
uj5u.com熱心網友回復:
Xamarin.Android 或 Xamarin.iOS 不支持 System.Drawing.Bitmap。
如果您打算在螢屏上顯示它,那么您需要位圖的 Android 變體和 iOS UIImage。
uj5u.com熱心網友回復:
Android Bitmap 也有GetPixel方法,替換System.Drawing.Bitmap為 即可Android.Graphics.Bitmap,需要在 android 平臺(有依賴服務)進行。
public Android.Graphics.Bitmap convertCvToBitmap(Mat img)
{
byte[] temp_img = this.convertCvToImage(img);
Android.Graphics.Bitmap mp = BitmapFactory.DecodeByteArray(temp_img, 0, temp_img.Length);
return mp;
}
參考
比較 Android 中的位圖影像
如何將位元組陣列中的影像檔案資料轉換為位圖?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/386822.html
