2

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

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

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

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?

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
  • Does [this](http://stackoverflow.com/questions/7669311/is-there-a-way-to-convert-a-system-io-stream-to-a-windows-storage-streams-irando) help at all? – Paul Feb 24 '16 at 15:32
  • @ Paul - Thanks. I saw this post earlier. However, I am using Xamrin.Forms. Thus, the code provided in the example does not appear to be supported on Xamarin's platform. – Scott Nimrod Feb 24 '16 at 15:35
  • Are you or have you tried using a dependency service? – Paul Feb 24 '16 at 15:37
  • No... I am able to load an image on PageA. However, when I attempt to pass the same stream object to PageB for it to load the same image, I get all of a sudden get this error. Hence, this works without a dependency service on PageA. As a result, I don't think it should matter for PageB. – Scott Nimrod Feb 24 '16 at 15:41

1 Answers1

0

Same problem i was facing, Please follow following step.

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

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

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.Create a method in your xaml.cs page.

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. Call "OnImages()" method from other class like ViewModel. and change image at run time.