【发布时间】:2020-09-16 19:24:56
【问题描述】:
在我的应用程序中,我需要将图像从一个页面传递到另一个页面图像视图来显示。我正在用相机拍照并做一些事情,然后我想将这些图像发送到第二页。
if (await isCamAvailable())
{
MediaFile photo1 = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions() { Directory = "NewBusiness", Name = "image1.jpg", PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = 1024, CompressionQuality = 95 });
if (photo1 != null)
{
PhotoImage1.Source = ImageSource.FromStream(() => { return photo1.GetStream(); });
countList.Remove("a");
countList.Add("a");
}
}
然后我通过这样做将它添加到字符串数组中
private List<string> sendImgList = new List<string>();
sendImgList.Add(createImgByteString(photo1.GetStream()));
private string createImgByteString(Stream data)
{
var bytes = new byte[data.Length];
return Convert.ToBase64String(bytes);
}
然后从第二页开始(为了测试,我只添加了一张图片)
foreach (string ss in imgList) {
byte[] Base64Stream = Convert.FromBase64String(ss);
imgView.Source = ImageSource.FromStream(() => new MemoryStream(Base64Stream));
}
我遵循了这个例子。但图片没有显示。
https://forums.xamarin.com/discussion/139360/how-to-transfer-images-from-one-page-to-another
也在 logcat 中得到这个..
[0:] ImageLoaderSourceHandler: Image data was invalid: Xamarin.Forms.StreamImageSource05-29 14:22:43.758 W/monodroid-assembly( 8737): typemap: unable to find mapping to a Java type from managed type 'System.Byte, mscorlib'
【问题讨论】:
标签: xamarin.forms