0
votes

Using Xamarin Forms and the NuGet FFImageloading plugin, I want to specify OS specific image paths in my XAML code like this:

     <ffimageloading:CachedImage DownsampleToViewSize="False" Aspect="AspectFill">

        <ffimageloading:CachedImage.Source>
           <OnPlatform x:TypeArguments="ImageSource"   
              iOS="MyProject.iOS.Resources.header_background.png" 

   Android="MyProject.Droid.Resources.Drawable.header_background.png" />
        </ffimageloading:CachedImage.Source>

     </ffimageloading:CachedImage>

The iOS image is declared as BundleResource, while the image for Android is declared as AndroidResource. On iOS, the image is loading properly but for Android I keep getting this error:

invalid resource directory name: Error APT0000: obj/Debug/res/ myproject.droid.resources.drawable.header_background.png (APT0000) (MyProject.Android)

What is wrong? Wrong build type for image? I don't get it.

2

2 Answers

0
votes

Image sources in Xamarin.Forms are based on default paths, and this has advantages, rather than direct file paths.

Place your images in

  1. Android - /Resources/drawable
  2. iOS - /Resources or as an asset
  3. UWP - root project folder

Then you just reference it by name header_background.png.

This has added advantages, in that you can place @2x or greater images for iOS, and place images in drawable-hdpi or other types of drawable folders in Android, and the OS will determine the most appropriate one to get.

0
votes

You have same filename header_background.png for both platforms.. So setting Source="header_background.png" property will read automatically form droid and ios projects in appropriate resources.