_This issue has been moved from a ticket on Developer Community._
I have and Image that gets added on an AbsoluteLayout on runtime. The Image.Source is from a MemoryStream:
System.IO.MemoryStream pictureBytes = new System.IO.MemoryStream(rowType.Picture); //(rowType.Picture is a BLOB field on a SQLite table Image deviceImage = new Image(); deviceImage.Source = ImageSource.FromStream(() => pictureBytes); AbsoluteLayout.SetLayoutBounds(deviceImage, new Rectangle(0, 0, RowDevice.Width, RowDevice.Height)); thisAbsoluteLayout.Children.Add(deviceImage);
This code always worked fine but recently (possibly since last updated Xamarin.Forms 4.7.0.1080) I am having an issue.
Now the ImageSource still loads fine but it I minimize the window (suspend) and then restore it (resume) the picture disappear.
I get this error message in the Output in Visual Studio:
Image loading: Image load failed: System.NotSupportedException: Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking. at System.IO.WindowsRuntimeStreamExtensions.AsRandomAccessStream(Stream stream) at Xamarin.Forms.Platform.UWP.StreamImageSourceHandler.LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken) at Xamarin.Forms.Platform.UWP.ImageExtensions.ToWindowsImageSourceAsync(ImageSource source, CancellationToken cancellationToken)
Looks to me like when the app is suspended the pictures get unloaded (free up memory?) but then the runtime cannot find them anymore.
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
(no solutions)
Can you please attach a small project that demonstrates this issue? Thanks!
I can confirm this issue with 4.7.0.1179
@sude22 Can you please attach a small project that demonstrates this issue? Thanks!
@samhouts Sorry, I created a small project, but the error is not reproducible :(
Thanks please reopen when you can reproduce the issue.
Hi, I created a sample app that reproduce the issue.
Please run the UWP project. Database should copy by itself and you will see an icon loaded from the database.
When the app is suspended and resumed the icon disappear (error described above).
Thanks please reopen when you can reproduce the issue.
I posted a sample project in comment. Can the issue be reopened?
I would also vote for reopen this issue.
I have the same problem
@rmarinho @samhouts Since there is a small project that demonstrates the issue, could you please reopen this bug?
Hi,
this is still not working. Is anybody monitoring this thread or would be better to open a new one?
I noticed the description for FromStream says "The delegate provided to stream must return a new stream on every invocation." With that in mind, I was able to get mine working by moving the MemoryStream directly into the FromStream function, going from this:
var stream = new MemoryStream(bytes);
var imgSource = ImageSource.FromStream(() => stream);
to this:
var imgSource = ImageSource.FromStream(() => new MemoryStream(bytes));
@tstrickler4 : Thank you very much for that hint.
For my defense, in the docs it is not mentioned that it has to be a new memorystream.
Your solution is working for me, too.
@tstrickler4 Thank you very much! This works perfectly now.
@sude22 @Realgigabyte Glad I could help!
Most helpful comment
Hi,
this is still not working. Is anybody monitoring this thread or would be better to open a new one?