Xamarin Forms - Android Application

OmegaPrimeOmegaPrime USMember ✭✭

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 2
        <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 2

    @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.

Sign In or Register to comment.