如何解决ImageSource IRandomAccessStream寻求不支持的错误? [英] How do I resolve an ImageSource IRandomAccessStream seeking not supported error?

查看:91
本文介绍了如何解决ImageSource IRandomAccessStream寻求不支持的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过 ImageSource 分配加载图像时,我收到以下运行时错误.

I am receiving the following runtime-error when attempting to load an image via ImageSource assignment.

不能将指定的流用作Windows运行时IRandomAccessStream,因为此流不支持查找.

Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking.

具体来说,我正在将ImageSource对象从一页传递到另一页. 因此,我很惊讶收到此错误.

Specifically, I am passing an ImageSource object from one page to another page. Thus, I am surprised that I am receiving this error.

我什至尝试从ImageSource对象中提取流对象. 但是,似乎不支持此功能.

I have even tried extracting the stream object from the ImageSource object. However, this does not appear to be supported.

任何人都可以提供有关如何解决此问题的指导吗?

Can anyone provide guidance on how I can resolve this issue?

推荐答案

我正面临着同样的问题, 请按照以下步骤操作.

Same problem i was facing, Please follow following step.

1.在您的xaml页面中添加一个img标签

1.In your xaml page add like this a img tag

图像x:Name ="productImage" Source ="{Binding SelectedSalesItem.Source}"
2.在任何网格上调用称为波纹管方法"的ItemSelected ="OnSalesItemSelected"事件.

Image x:Name="productImage" Source="{Binding SelectedSalesItem.Source}"
2. on any grid call ItemSelected="OnSalesItemSelected" event called bellow method.

公共异步无效OnSalesItemSelected(对象发送者,EventArgs参数){

Public async void OnSalesItemSelected(object sender, EventArgs args) {

        try
        {

            if (SaleVm.SelectedSalesItem != null)
            {
                OnImages();//Call point no 3 method "OnImages"
            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

3.在xaml.cs页面中创建一个方法.

3.Create a method in your xaml.cs page.

异步void OnImages(){

async void OnImages() {

        try
        {

            if (SaleVm.SelectedSalesItem != null)
            {

                IFolder rootFolder = FileSystem.Current.LocalStorage;
                IFolder imageFolder = await rootFolder.GetFolderAsync("ItemsImg");
                IFile imageFile = await imageFolder.GetFileAsync(SaleVm.SelectedSalesItem.ItemCode + ".png");
                var stream = await imageFile.OpenAsync(FileAccess.Read);
                productImage.Source = ImageSource.FromStream(() => stream);
            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

4.从其他类(如ViewModel)调用"OnImages()"方法. 并在运行时更改图像.

4. Call "OnImages()" method from other class like ViewModel. and change image at run time.

这篇关于如何解决ImageSource IRandomAccessStream寻求不支持的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆