locked
ImageSource.FromStream displays no image on Samsung Devices only. RRS feed

  • Question

  • User190819 posted

    So I have this simple piece of code that so far works on iOS, Android, and UWP, but seemingly I can't get the image to display on Samsung devices. Customers have called in and they are running various Samsung devices ranging from low end Tab 3 Lites to the latest Galaxy.

    Basically when a user interacts with a Bluetooth Device, it sends the byte array ImageData and displays it on a XAML Image control DisplayImage. The Bluetooth Hardware captures data in my .Droid project, the following code in the PCL. The data sent is a plain bitmap.

    DisplayImage.Source = ImageSource.FromFile (DeviceManager.WaitingForUser);

    and

    DisplayImage.Source = ImageSource.FromStream (() => new MemoryStream (ImageData));

    Is there something specific to Samsung that would prevent it from working?

    Tuesday, March 14, 2017 8:42 PM

Answers

  • User190819 posted

    So, I identified it further. It isn't just change of ImageSource on samsung, it is a change from PNG to BMP. So to correct, I just simply updated the interface and platform code to provide the stream in PNG on Samsung devices if it is needed. Peculiar situation identified, but it is there.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 15, 2017 7:25 PM

All replies

  • User190819 posted

    I should be more specific, FromFile works 100%.

    Tuesday, March 14, 2017 8:43 PM
  • User180523 posted

    I have a Samsung TabE if you need another dev who can test in a meaningful way.

    Just a thought, as a test... You should be able to save the image you receive, then open it in the standard gallery photo viewer. If that doesn't work either that might lead you in a given direction... I mean if the file isn't a proper file that any other app can open it may not be the image or the memory-stream, but maybe how data is being received over Bluetooth; as an example.

    I know I had a similar issue trying to pass images from a USB attached scanner. I had no choice but to save the image from the scanner to the device's sd drive, then read it back out again. Something in the write/read process fixed up the stream. Maybe there is a weird byte-ordering going on... or some other silliness.

    Tuesday, March 14, 2017 8:56 PM
  • User190819 posted

    I can definitely go ahead and see if I can use the photo viewer to view. I just know that tested on Nexus 6P, Blackberry Priv, and Nexus 5, it all functioned as expected. Does seem specific to Samsung.

    Tuesday, March 14, 2017 9:01 PM
  • User263 posted

    I can confirm that we are using ImageSource.FromStream successfully with XF and Samsung devices.

    Tuesday, March 14, 2017 9:27 PM
  • User190819 posted

    So tested with saving the file and opening it up in Gallery, it saved and was viewable on the device, just specifically not in Xamarin.Forms.

    I have a very similar native app for Android and the image data did display. This is specific to Samsung using Xamarin Forms.

    I am wondering if it could be switching between FromStream and FromFile in the code?

    Tuesday, March 14, 2017 9:53 PM
  • User190819 posted

    So I do use FromStream elsewhere in the program where it is the only StreamImageSource throughout its execution and it works fine. So it seems to be only if I am switching between the two ImageSources.

    Tuesday, March 14, 2017 10:08 PM
  • User180523 posted

    So it seems to be only if I am switching between the two ImageSources.

    Good job of detective work. So... What if you have two images on your page on top of each other? When you have an image from the bluetooth source it will lay on top of the "waiting for user" image. No fancy source switching.

    Wednesday, March 15, 2017 9:22 AM
  • User190819 posted

    So, I identified it further. It isn't just change of ImageSource on samsung, it is a change from PNG to BMP. So to correct, I just simply updated the interface and platform code to provide the stream in PNG on Samsung devices if it is needed. Peculiar situation identified, but it is there.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 15, 2017 7:25 PM
  • User180523 posted

    Wow... Good work. Thanks for sharing that. So the Samsung doesn't like it when you change formats of the image. That's weird. I wonder if it might be related to 'bitness'... Going from a 4bit image to a 32bit image (which has transparancy) for example.

    Thanks for sharing your hard research with the community!

    Wednesday, March 15, 2017 7:33 PM