locked
How to manage images and page background images ? RRS feed

  • Question

  • User387084 posted

    Hi guys,

    I am facing an issue with images, specially with Android builds, although I follow Xamarin doc guidelines. I have a background images named background.jpg, located in : - MyProject : root folder - MyProject.Android : Resources/drawable ==> I created the drawable folder, as it did not exist ; Build Action: AndroidResource - MyProject.UWP : root folder ; Build Action: Content - MyProject.iOS : in a new image set, I put only the image in Vector (.pdf file), as mentionned in Xamarin doc

    When I try to use this image (can't test on iOS) : - As ContentPage.BackgroundImageSource : it doesn't work (image is not loaded), unless I use it as a MyProject resource (BackgroundImageSource = ImageSource.FromResource("MyProject.background.jpg");) that I don't want because I may want to manage multiple resolutions... - As a simple Image in XAML (Image Source="background.jpg") : works on UWP, but not on Android (emulator) with exception : Unhandled Exception: Java.Lang.RuntimeException: Timeout exceeded getting exception details

    What am I doing wrong ? Thanks

    Sunday, July 14, 2019 9:28 PM

Answers

  • User379860 posted

    Ok. Thanks for your sharing, You can create a new emulator to test this issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, July 16, 2019 8:10 AM

All replies

  • User379860 posted

    You can put the image to the Resources/drawable folder in android .If you want manage multiple resolutions, you can put diferent images of resolutions to the these folders(drawable-hdpi ,drawable-xhdpi...) with same name, android will use them automaticlly.

    You want to set the background Image for ContentPage, you could set new ContentPage() { BackgroundImage= "background.JPG" }; in xaml.cs file

    set the BackgroundImage in the xaml file

         <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:NaViDemo"
             x:Name="myContentpage"
             x:Class="NaViDemo.MainPage" 
             BackgroundImage="background.JPG">
    

    If you just want to add a image to XAML. You can add this image like following code.

        <Image
            Source="background.JPG"
            />
    
    Monday, July 15, 2019 3:08 AM
  • User387084 posted

    Thanks LeonLu but that is EXACTLY what I already did.

    Monday, July 15, 2019 6:54 AM
  • User379860 posted

    @galactose If you opreate above steps, you still get the same error or you still cannot set the image in Image or Background of ContentPage

    Monday, July 15, 2019 8:56 AM
  • User387084 posted

    Hi,

    It seems to be a problem with the emulator. I did not change anything and while it is not working on the emulator, it works very fine on a real Android device. I hope it's not the API level (27 in emulator, 28 in device).

    Thanks !

    Monday, July 15, 2019 11:42 AM
  • User379860 posted

    Ok. Thanks for your sharing, You can create a new emulator to test this issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, July 16, 2019 8:10 AM