Bug 43809 - Image size is inconsistent when loading with ImageSource.FromResource or ImageSource.FromStream
Summary: Image size is inconsistent when loading with ImageSource.FromResource or Imag...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: All All
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/williamwilling/xam...
Depends on:
Reported: 2016-08-27 16:11 UTC by Joost Ronkes Agerbeek
Modified: 2017-08-07 16:19 UTC (History)
5 users (show)

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

Zip of git repo with fixes (696.65 KB, application/x-zip-compressed)
2016-10-05 16:12 UTC, Chris King

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 for Bug 43809 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Joost Ronkes Agerbeek 2016-08-27 16:11:50 UTC
# Steps to reproduce

Download the code sample from https://github.com/williamwilling/xamarin-forms-image-size or follow the steps below.

1. Create a new Xamarin Forms PCL project.
2. Add a new XAML page.
3. Add the following code to the XAML.

  <Image x:Name="ResourceImage" HorizontalOptions="Center" VerticalOptions="Center" />
  <Image x:Name="FileImage" HorizontalOptions="Center" VerticalOptions="Center" />
4. Add the following code to the constructor of the page in the code behind.

ResourceImage.Source = ImageSource.FromResource("TestApp.test.png");
FileImage.Source = ImageSource.FromFile("test.png");
5. Add an image called `test.png` to the portable project and set `Build Action` to `Embedded Resource`.
6. Add the same image to the `Resources/drawable/` folder of the Android project and set `Build Action` to `AndroidResource`.
7. Add the same image to the `Resources/ folder` of the iOS project and set `Build Action` to `BundleResource`.
8. Add the same image to the root folder of the UWP project and set `Build Action` to `Content`.
9. Set the test page as the starting page in `App.cs`.
10. Build and run the project on each platform.

# Expected behavior

All platforms should show the same picture twice, at full size in both cases. (Maybe smaller if the image doesn't fit in its parent, but at least both images should have the same size.)

# Actual behavior

* UWP exhibits the expected behavior.
* iOS shows the image loaded with `ImageSource.FromFile` at full size, and the image loaded with `ImageSource.FromResource` at half size.
* Android shows the image loaded with `ImageSource.FromFile` at full size, and the image loaded with `ImageSource.FromResource` at one-third the size.

Using `ImageSource.FromStream` instead of `ImageSource.FromResource` gives the same results, regardless of whether the stream is created from an embedded resource or from a file on the file system.

# Supplemental info (logs, images, videos)

Code available at https://github.com/williamwilling/xamarin-forms-image-size

# Test environment (full version information)

* Xamarin Forms v2.0.0.6482 and v2.3.1.114
* Android 5.0 (API 21)
* iOS 9.3
* Windows 10, Build 1056 with UWP v5.0.0 and v5.2.2

Developed with Visual Studio Enterprise 2015 with all updates installed.
Comment 1 Chris King 2016-10-05 16:12:52 UTC
Created attachment 17889 [details]
Zip of git repo with fixes

Relative image sizes differ between platforms.