How to display the image file

TS44 81 Reputation points
2020-12-10T23:05:39.43+00:00

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.

47131-pic.png

Currently,

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"));

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

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,251 Reputation points Microsoft Vendor
    2020-12-11T02:22:02.38+00:00

    Hello,​

    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:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#embedded-images

    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