How to display the image file

TS44 81 Reputation points

If the image file is placed in the configuration as shown below,
What is the most efficient way to display an image?
* I would like to display it in consideration of the burden on the application.



Properties:Build actions:Embedded Resource
Button1.ImageSource = ImageSource.FromStream(() => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("SampleApp.pic.SAMPLE.png"));
Button2.ImageSource = ImageSource.FromStream(() => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("SampleApp.pic.SAMPLE2.png"));

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,287 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 67,631 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    What is the most efficient way to display an image?

    Put the image to the PCL and set the build action is Embedded Resource, it is not efficient way, this way like put your image to the local storage, you have to do the file I/O to read it. You can see offical article:

    The efficient way: This method of distributing images is recommended when identical images are used on each platform, and is particularly suited to creating components, as the image is bundled with the code. For example:

    IOS => You need put the images on "Resources" (note: no more routes) , for ANDROID => you need put the images on "Resources/drawable" .for UWP => put the images on root project UWP.

    On Diferents platforms the images have diferents routes.

    Then on the xaml files you can put <Image Source="imageName.jpg" />

    Best Regards,

    Leon Lu

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments