locked
ImageSource.FromResource using PCL and loading from each platforms resources folder RRS feed

  • Question

  • User26235 posted

    Another image question. I was using Shared Projects previously but decided to switch to use a PCL w/ Xamarin.Forms and my previous ImageSource.FromResource code doesn't work since the resource is no longer in the assembly it's being called from (my PCL assembly now rather than the platform assembly at runtime). Do I have to use an interface to have the call occur from the platform assemblies now?

    I am placing the images in each platforms respective resources folder, setting BuildAction = EmbeddedResource, and ResourceID = "image" and in the PCL using ImageSource.FromResource("image")

    The reason I want to use this approach is I noticed that you can still take advantage of the naming conventions from each platform if you place the images in their native locations but you can still have the shared code to load the image.

    Thursday, June 12, 2014 7:14 PM

Answers

  • User14 posted

    See the Working with Images doc and example.

    If you are placing the images in each platform app project, you can use different Build Actions and ImageSource.FromFile -- this lets you support Retina on iOS and the hdpi variants on Android.

    If you want to keep using BuildAction:EmbeddedResource then yes, continue using ImageSource.FromResource.

    The doc has a little section on debugging that helps you list all the resources if they don't seem to be working for you.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 12, 2014 7:25 PM

All replies

  • User14 posted

    See the Working with Images doc and example.

    If you are placing the images in each platform app project, you can use different Build Actions and ImageSource.FromFile -- this lets you support Retina on iOS and the hdpi variants on Android.

    If you want to keep using BuildAction:EmbeddedResource then yes, continue using ImageSource.FromResource.

    The doc has a little section on debugging that helps you list all the resources if they don't seem to be working for you.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 12, 2014 7:25 PM
  • User26235 posted

    Sorry about that one I must've scanned over that section accidentally. I downloaded the sample using PCL. I set my BuildAction to BundleResource in iOS and AndroidResource in Android and using ImageSource.FromFile I can load the native resolutions. Thanks!

    Thursday, June 12, 2014 7:54 PM
  • User234031 posted

    Hi!

    How do I set Page BackgroundImage property if I am using ImageSource.FromResource ?

    Thank you!

    Wednesday, June 29, 2016 7:22 PM
  • User234031 posted

    Hi,

    Another question about ImageSource.FromResource:

    How it behaves in relation to files @2x and @3x?

    Do I have to explicit specify the @2x and @3x file names?

    Thank you!

    Wednesday, June 29, 2016 9:39 PM
  • User179286 posted

    To your second question: 2x etc. Names have no impact on images stored as embedded resource

    Thursday, June 30, 2016 6:10 AM
  • User234031 posted

    Thank you!

    Sunday, July 3, 2016 6:27 PM