ImageSource.FromStream()无法在某些Android设备上运行

时间:2016-06-12 19:39:15

标签: android xamarin xamarin.forms

我的内容页面上有Image元素。我想在MemoryStream的构造函数中为其分配ContentPage源代码。这在三星Galaxy A3(Android 5.0.2)上运行正常,但在Samsung Galaxy Note 3(Android 5.0)上没有显示任何内容(没有错误,没有例外,没有图像)。这是Xamarin.Forms中的错误吗?或者我做错了什么?

代码:

Image image = new Image();
var path = "some/path/to/image.jpg";
var bytes = File.ReadAllBytes(path); //has correct byte array with correct length
image.Source = ImageSource.FromStream(() => new MemoryStream(bytes)); 

1 个答案:

答案 0 :(得分:2)

我有同样的问题。

但是在相机中选择较低分辨率,图像有效,我需要选择分辨率< 9 Mpx和图像工作,分辨率更大,图像不起作用。 它取决于Android版本和设备,它是一个内存不足的例外。

因此,我调整了使用相机拍摄的图像的大小并且可以正常工作。

你可以安装FFimageLoading插件和CachedImage控件,我不测试它,因为我更喜欢调整图像大小,应用程序更大的插件。