Bug 22666 - ImageSource.FromStream fails on Android but works on iOS
Summary: ImageSource.FromStream fails on Android but works on iOS
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-09-04 19:29 UTC by Adrian
Modified: 2016-03-16 12:31 UTC (History)
8 users (show)

Is this bug a regression?: ---
Last known good build:

Xamarin.Forms page that shows the problem (861 bytes, application/octet-stream)
2014-09-05 18:21 UTC, Adrian

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Adrian 2014-09-04 19:29:28 UTC
I have a BMP image in a memory stream, when I use the following code in Android I get the following error reported:
[skia] --- decoder->decode returned false

Here is the code:
TestImage.Source = ImageSource.FromStream(() => newImage);

If I write the memory stream out to a temp file and load the same image from a file it works using the following:
string tempFile = await WriteToTempFile(newImage);
TestImage.Source = ImageSource.FromFile(tempFile);

Note that iOS works just done using a memory stream for the same image!

The problem appears to be a known bug in Android that could easily be solved if the underlying Xamarin code implements the FlushedInputStream solution at https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/library/src/com/nostra13/universalimageloader/core/assist/FlushedInputStream.java

Note there is a forum post about this and JPG and PNG but it also applies to BMP - this post is http://forums.xamarin.com/discussion/16500/bitmap-decode-byte-array-skia-decoder-returns-false

So my cross-platform PCL file ha sot use PCLStorage to write to a temp dil even on platforms that don't have the problem - not ideal.
Comment 1 Adrian 2014-09-04 19:31:24 UTC
Sorry about my last para (I blame the glass of red wine I just had :-), it should have read:

So my cross-platform PCL file has to use PCLStorage to write to a temp file even on platforms that don't have the problem - not ideal.
Comment 2 Parmendra Kumar 2014-09-05 06:30:03 UTC
I have tried to reproduce this issue and unable to reproduce it. Could you please provide us the sample project or environment info to reproduce this issue ?.
Comment 3 Adrian 2014-09-05 18:21:15 UTC
Created attachment 7953 [details]
Xamarin.Forms page that shows the problem
Comment 4 Adrian 2014-09-05 18:25:15 UTC
Note: On the most recent version of Android (I'm using the Google Nexus simulator) the attached example works.

However, on a real HTC Desire C running Android 4.0.3 it fails, it also fails on other devices too.

So, maybe Google have fixed the bug in the most recent version of Android (?) but of course that accounts for a small percentage of the user base who generally are using older versions of Android.
Comment 5 Parmendra Kumar 2014-09-08 11:54:34 UTC
I have checked this issue with given sample on Comment 3 and observed the different behavior on iOS and Android.

Screencast: http://screencast.com/t/LLYcLOBLpTo
IDE Log: https://gist.github.com/saurabh360/0e0b59d076fb64b5570e

Environment Info:

=== Xamarin Studio ===

Version 5.3 (build 440)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 77efa3f
Build date: 2014-08-26 07:59:55-0400

=== Build Information ===

Release ID: 503000440
Git revision: accb55419539e512cff857b14b80ec3107996511
Build date: 2014-09-01 08:53:05-04
Xamarin addins: 6dbac4b3a32df080bf98cde838ce89e573a92859

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 6 Rui Marinho 2015-06-01 06:59:59 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. 
The App.cs file doesn't refer to any code using ImageSource.FromStream.
If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue we would very much appreciate it. We monitor recently touched NEEDS INFO bugs so we’ll notice you attached the reproduction we’ll take it from there. 

Warm regards,
Xamarin Forms Team
Comment 7 Shane Siebken 2015-07-23 00:18:16 UTC
I am also running into this exact issue. I will try to reproduce in the next few weeks. Cheers!
Comment 8 Jason Smith [MSFT] 2016-03-16 12:31:26 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we no longer believe it affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team