来自 Xamarin.Forms 中 MemoryStream 的图像为空



在我的应用程序中,图像必须从字节数组打开。但是组件"图像"无法打开它。他是空的。

public OpenImage (byte[] bin)
        {
            InitializeComponent ();
            Image image = new Image { Source = ImageSource.FromStream(() => new MemoryStream(bin)) };
            this.Content = image;
        }

我会像下面这样做:

 var imgSource = ImageSource.FromStream(() => new MemoryStream(bin));       
  Image myImage =new Image { Source =imgSource };
   This.Content=myImage;

确保 bin 不为空,并且它有一个图像作为字节。

事实上,

在我的应用程序中,错误的是从 JSON 转换数据。需要改变

byte[] bin = Encoding.Default.GetBytes(json);

byte[] bin = JsonConvert.DeserializeObject<byte[]>(json);

最新更新