Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin表单-从Blob存储加载ImageSource_C#_Binding_Xamarin.forms_Imagesource_Azure Blob Storage - Fatal编程技术网

C# Xamarin表单-从Blob存储加载ImageSource

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()

我面临着一个有点奇怪的问题。 我在Xamarin Forms项目中有一个简单的代码(我猜),可以通过这个伟大的插件拍照。允许跨平台拍照的媒体:

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));
    }
}