【问题标题】:How do I resolve an ImageSource IRandomAccessStream seeking not supported error?如何解决 ImageSource IRandomAccessStream 寻求不支持的错误?
【发布时间】:2016-08-31 18:18:57
【问题描述】:

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

无法将指定的流用作 Windows 运行时 IRandomAccessStream,因为此流不支持搜索。

具体来说,我将一个 ImageSource 对象从一个页面传递到另一个页面。 因此,我很惊讶我收到了这个错误。

我什至尝试从 ImageSource 对象中提取流对象。 但是,这似乎不受支持。

谁能提供有关如何解决此问题的指导?

【问题讨论】:

  • this 有帮助吗?
  • @ Paul - 谢谢。我之前看过这个帖子。但是,我使用的是 Xamrin.Forms。因此,示例中提供的代码似乎不受 Xamarin 平台的支持。
  • 您是否尝试过使用依赖服务?
  • 不...我可以在 PageA 上加载图像。但是,当我尝试将相同的流对象传递给 PageB 以使其加载相同的图像时,我突然得到了这个错误。因此,这可以在没有 PageA 上的依赖服务的情况下工作。因此,我认为这对 PageB 来说并不重要。

标签: xamarin.forms


【解决方案1】:

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

1.在你的xaml页面中添加这样一个img标签

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

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 页面中创建一个方法。

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()”方法。 并在运行时更改图像。

【讨论】:

    猜你喜欢
    • 2015-01-09
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    相关资源
    最近更新 更多