[英]How to show images from device storage in Xamarin.Forms?
I need to set the Source
property of an image to the path returned after the user has picked it from gallery or camera (using Plugin.Media) the path looks like this: 我需要将图像的
Source
属性设置为用户从画廊或相机(使用Plugin.Media)中选择图像后返回的路径,该路径如下所示:
/storage/emulated/0/Android/data/com.company.myApp/files/Pictures/temp/Screenshot_20181225-134128_6.jpg
I tried this 我试过了
ImageSource.FromUri(new Uri(file.FilePath, UriKind.RelativeOrAbsolute));
but the image doesn't show anything, 但是图像什么也没显示
you can create an object of MediaFile like, 您可以创建MediaFile对象,例如
public MediaFile AttachedImage;
and store captured image into it so that your below issue will resolved, this exception is thrown: System.ObjectDisposedException: Cannot access a disposed object. 并将捕获的图像存储到其中,以便解决以下问题,将引发此异常:System.ObjectDisposedException:无法访问已处置的对象。 Object name: 'Stream has been closed .
对象名称:'流已关闭 。 you can get Image Stream any time from that object like,
您可以随时从该对象获取图像流,例如,
img.Source = AttachedImage.GetStream().
it will sure resolve your issue. 它一定会解决您的问题。
Media Plugin returns a file with the path. Media Plugin返回带有路径的文件。 You have to use this, for the file:
您必须使用此文件:
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.