0
   <Image Source="{Binding s, Mode=OneWay}"></Image>

with a StreamImageSource-Property:

 public ImageSource s { get; set; }

Throws following exception:

Failed to create image decoder with message 'unimplemented' [0:] ImageLoaderSourceHandler: Image data was invalid: Xamarin.Forms.StreamImageSource

I wonder why this happens? I guess I have to create a Converter, but I dont know what I am supposed to convert? Which argument is correct for Image.source ?

actopozipc
  • 31
  • 3

2 Answers2

0

If you put the image to each platform,you could use ImageSource = ImageSource.FromFile("xxx.png").

If you put it in the forms project and set it Build Action as EmbeddedResource,you could use ImageSource.FromResource(Source, typeof(your class).GetTypeInfo().Assembly)

You could look at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images.

And here is an answer which have achieve the two methods above.You could refer to it. https://stackoverflow.com/a/56315412/10768653

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23
  • Sadly I cant use Uri or a File, Im using a picture that the user selected from their own gallery Thats why I am also handling with a StreamImageSource – actopozipc Jul 26 '21 at 12:30
0

It seems like Streams get disposed and closed as soon as one uses them to create a source. Thats why the Image data was "invalid", because there was no image to read from a closed stream. My solution was to create a copy from the stream everytime I use it.

 ImageSource.FromStream(() => new MemoryStream(stream.ToArray()));
actopozipc
  • 31
  • 3