Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to display the image file

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.

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

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    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://docs.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" />


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    @Techno_Develop Are there any update for this issue, please reply is helpful, please click the Yes tab under the helpful answer. If you post an other thread, please accept it as well.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.