xamarin/Xamarin.Forms

ImageSource.FromFile strange work

Open

#5,631 opened on Mar 20, 2019

 (1 comment) (0 reactions) (0 assignees)C# (1,926 forks)batch import
3.3.0e/3 :clock3:help wantedi/lowi/regressioninactivep/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

Setting image source from file path works differently depending on file location and on Xamarin Forms version. The following code in xaml leads to different image sizes (see screenshots) with different Xamarin Forms versions.

<StackLayout Orientation="Vertical"> <Image Source="Octocat.png" Aspect="AspectFit"/> <Image Source= "/data/user/0/com.companyname.ImageSourceExample.Android/files/Octocat.png" Aspect="AspectFit"/> </StackLayout>

Images in drawable folder and in app folder are the same, but using Xamarin.Forms version 3.2.0.871581 (or lower) I get 2 same sized images and in version 3.3.0.912540 (or higher) I get second image much smaller.

I can reproduce this behavior only on Visual Studio Emulator for android, on real devices I have no such problem.

Steps to Reproduce

  1. Create new Xamarin Forms project in Visual Studio
  2. Add the same image to drawable folder and to the app folder on a virtual device
  3. Add two images with source from files from step 2.
  4. Start app on Visual Studio Android Emulator with different Xamarin Forms (3.2.0.871581 and 3.3.0.912540) versions.

Expected Behavior

Get same images sizes for the same code independently from Xamarin Forms version.

Actual Behavior

Different images sizes for the same code for different Xamarin Forms version

Basic Information

  • Version with issue:3.3.0.912540
  • Last known good version: 3.2.0.871581
  • IDE: Visual Studio 2017, ver. 15.9.7
  • Platform Target Frameworks:
  • Affected Devices: Visual Studio Emulator for Android

Screenshots

imgsource_fine imgsource_wrong

Reproduction Link

https://github.com/dronishe/XamarinImagFromSourceExample

I’ve created a simple repo for reproduction. Last commit – same image size with older version of Xamarin Forms. Second to last commit – same code, differs only with Xamarin Forms version. Images have different size.

Contributor guide