C# Xamarin表单-从Blob存储加载ImageSource
我面临着一个有点奇怪的问题。 我在Xamarin Forms项目中有一个简单的代码(我猜),可以通过这个伟大的插件拍照。允许跨平台拍照的媒体:C# Xamarin表单-从Blob存储加载ImageSource,c#,binding,xamarin.forms,imagesource,azure-blob-storage,C#,Binding,Xamarin.forms,Imagesource,Azure Blob Storage,我面临着一个有点奇怪的问题。 我在Xamarin Forms项目中有一个简单的代码(我猜),可以通过这个伟大的插件拍照。允许跨平台拍照的媒体: public async Task<CameraResult> TakeCrossPictureAsync() { var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions); CameraResult res = new CameraResult()
public async Task<CameraResult> TakeCrossPictureAsync()
{
var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
CameraResult res = new CameraResult()
{
Picture = ImageSource.FromFile(file.Path),
FilePath = file.Path,
Name = await this.UploadFileAsync(file.GetStream())
};
}
“Picture”属性是一个Xamarin.Forms.ImageSource。
然后,我导航到另一个页面,将ImageSource作为参数传递,并能够在另一个FFImageLoading:CachedImage
中显示它:
<ffimageloading:CachedImage Source="{Binding Picture}" LoadingPlaceholder="loading.png" CacheDuration="10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
没问题,一切都很顺利。
但是,当我尝试通过从Blob存储器下载图像来做同样的事情时:
public async Task<ImageSource> GetFileAsync(string name)
{
var blob = this.container.GetBlobReference(name);
if (await blob.ExistsAsync())
{
await blob.FetchAttributesAsync();
byte[] blobBytes = new byte[blob.Properties.Length];
await blob.DownloadToByteArrayAsync(blobBytes, 0);
Stream stream = new MemoryStream(blobBytes);
return(ImageSource.FromStream(() => stream));
}
}
公共异步任务GetFileAsync(字符串名称)
{
var blob=this.container.GetBlobReference(名称);
if(等待blob.ExistsAsync())
{
等待blob.FetchAttributesAsync();
byte[]blobBytes=新字节[blob.Properties.Length];
等待blob.DownloadToByteArrayAsync(blobBytes,0);
流=新的内存流(blobBytes);
返回(ImageSource.FromStream(()=>stream));
}
}
返回的Imagesource在第一个和第二个视图中绑定到相同的FFImageLoading:CachedImage
问题是,它在第一个视图中显示得非常完美,但当我将ImageSource
作为参数传递给第二个ViewModel时,图像不会显示在UWP项目中,并显示LoadingPlaceHolder,或者我在Android上遇到未处理的异常
有人能告诉我这两个图像源
有何不同,以及为什么它显示在第二个视图中的文件中,而不是从blob中
提前谢谢你
public async Task<ImageSource> GetFileAsync(string name)
{
var blob = this.container.GetBlobReference(name);
if (await blob.ExistsAsync())
{
await blob.FetchAttributesAsync();
byte[] blobBytes = new byte[blob.Properties.Length];
await blob.DownloadToByteArrayAsync(blobBytes, 0);
Stream stream = new MemoryStream(blobBytes);
return(ImageSource.FromStream(() => stream));
}
}