繁体   English   中英

将 byte[] 转换为 System.Drawing.Bitmap C# Xamarin.NET

[英]Convert byte[] to System.Drawing.Bitmap C# Xamarin.NET

我正在尝试一种可以将 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: '此平台不支持操作。'”。

我知道它来自这行代码: mp = new Bitmap(ms); (我在使用Console.WriteLine之前检查过它)

谁能知道这个问题,或者是否有其他路径可以将 Emgu.Cv.Mat 图像转换为 System.Drawing.Bitmap 图像?

谢谢!

System.Drawing.Bitmap is not supported in Xamarin.Android or Xamarin.iOS.

如果要在屏幕上显示它,则需要 Bitmap 的 Android 变体和 iOS Z98AA6B77D0908790DEAAZ55ABBBBBBBBBBBB。

Android Bitmap also has the method GetPixel , just replace System.Drawing.Bitmap with Android.Graphics.Bitmap , and you need to do this in android platform (with dependency service).

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 中的 Bitmap 图像

如何将字节数组中的图像文件数据转换为 Bitmap?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM