Xamarin Forms - Android Application

I am unable to get ANY image to show on an Android app built with Xamarin Forms. This application previously worked. I have checked that the images are lower case, that they are marked as AndroidResources and that there are no strange characters. I would greatly appreciate any help.

Answers

  • OmegaPrimeOmegaPrime USMember ✭✭

    A follow up, in console, all images when attempting to load return

    Could not load image named: {0}: app_background.png
    FileImageSourceHandler: Could not find image or image file was invalid: File: app_logo.png

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Seeing your actual markup and related code would help. Otherwise there's nothing for us to go on.
    Tips for posting code so the forum parser doesn't eat it.

    I can tell you that its not a framework/eco-system issue since images work for the rest of us.

  • OmegaPrimeOmegaPrime USMember ✭✭

    Here is the markup for the image,

      <Image Grid.Column="0"
          Grid.Row="0"
          Source="app_backarrow.png"
          VerticalOptions="Start"
          HorizontalOptions="Start"
          WidthRequest="25"
          HeightRequest="25"
          Margin="0,25,0,0">
        <Image.GestureRecognizers>
          <TapGestureRecognizer Tapped="Handle_Tapped"/>
          </Image.GestureRecognizers>
      </Image>
    

    I think it must be on the project level since I have another android project that works fine

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Things don't match up.
    The arrow is point to "app_background.jpg" and your markup is for "app_backarrow.jpg"

    So maybe the error is not happening on the page you think it is? Maybe its for a different Image than you're thinking?

  • OmegaPrimeOmegaPrime USMember ✭✭

    Its all images, no image will show, so I just grabbed one. Here is one the references the same image

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="XXX.Common.Ui.PageLogin"
    BackgroundImage="app_background.png"

  • OmegaPrimeOmegaPrime USMember ✭✭
    edited November 2017
        <Image Grid.Column="0"
            Grid.ColumnSpan="2"
            Grid.Row="0"
            Source="app_logo.png"
            VerticalOptions="Start"
            HorizontalOptions="Center"
            WidthRequest="140"
            HeightRequest="140"
            Margin="0,0,0,20"/>
    
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Its all images,

    Sounds like the resource file or proj file in the Android project is screwed up.
    You could try deleting all the images then re-adding them.
    Personally I like to just link to the real files in the PCL project so I only have one real image and the platform projects don't have copies that I have to keep in sync.
    https://redpillxamarin.com/2017/02/24/301-quikies-icon-strategy/

  • OmegaPrimeOmegaPrime USMember ✭✭

    So built a completely new Android project, same issue

    [0:] Could not load image named: {0}: app_background.png
    11-02 07:54:46.225 W/ResourceType( 3253): No package identifier when getting value for resource number 0x00000000
    [0:] FileImageSourceHandler: Could not find image or image file was invalid: File: app_logo.png

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    So built a completely new Android project, same issue

    What if you build a completely new Xamarin.Forms solution, then add one image to the generic "welcome to xamarin" default home page - just as a test?

  • NMackayNMackay GBInsider, University ✭✭✭✭✭
    edited November 2017

    @OmegaPrime

    Where are you putting your images? drawable-hdpi? I'm certainly not seeing this issue.

    I use this markup extension so you just pass the filename and not the extension, for android you don't need the extension.

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    
    namespace Foobar.Shared.Common.MarkupExtensions
    {
        [ContentProperty("SourceImage")]
        public class PlatformImageExtension : IMarkupExtension<string>
        {
    
            public string SourceImage { get; set; }
    
            public string ProvideValue(IServiceProvider serviceProvider)
            {
                if (SourceImage == null)
                    return null;
    
                string imagePath;
                switch (Device.RuntimePlatform)
                {
                    case Device.Android:
                        imagePath = SourceImage;
                        break;
                    case Device.iOS:
                        imagePath = SourceImage + ".png";
                        break;
                    case Device.UWP:
                        imagePath = "Images/" + SourceImage + ".png";
                        break;
                    case Device.WinPhone:
                        imagePath = "Images/" + SourceImage + ".png";
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                return imagePath;
            }
    
            object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
            {
                return ProvideValue(serviceProvider);
            }
        }
    }
    
    

    Usage:

    <customControls:ImageButton
                    Grid.Column="2"
                    Command="{Binding CloseCommand}"
                    Source="{markupExtensions:PlatformImage SourceImage='IconClose'}" />
    
  • OmegaPrimeOmegaPrime USMember ✭✭

    Images are in Resources/drawable.

    @ClintStLaurent I created a new solution with the barebones and the image shows as expected. So I am thinking that some reference somewhere is causing the issue.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Yep. Sounds like.

  • LindsayMilesLindsayMiles CAMember ✭✭

    Hi,

    I'm seeing the same/similar issue.

    Xamarin Forms project targeting Android and iOS. A drawing app...
    User can select a subject, list loads with a number of background template .png files to choose from.

    All .png files are in the Resources\drawable folder. All BuildAction set to Embedded Resource. And all are of similar size and dimensions.

    Some images are displayed, some are not, yet all are set and handled in the same way.

    If I change BuildAction to AndroidResource on images, all images are displayed yet only some display when BuildAction is Embedded Resource.

    Very odd behavior and not consistent with all images.

    Not tried in iOS yet.

Sign In or Register to comment.