How to display the image when the build action of the image file is the content

TS44 81 Reputation points

Currently, I am displaying an image using the build action of an image file as an embedded resource, but I do not know how to display the image when the build action is changed to content.

Someone please show me a sample

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

Accepted answer
  1. JarvanZhang 23,951 Reputation points


    Welcome to our Microsoft Q&A platform!

    1.To display the images in Xamarin.Forms, try placing the image file in the resource folder of the each platform project. Or if you place the files in the shared project, please set the Build Action to EmbeddedResource.

    To load images in Xamarin.Forms, you could check this document:

    2.For the file which is set Build Action to Content, the VS provides to Application.GetContentStream method to access the file. But it is only supported in ASP.NET, it doesn't work in the .Net Standard referenced by Xamarin.Forms.


    Best Regards,

    Jarvan Zhang

    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

1 additional answer

Sort by: Most helpful
  1. mc 4,111 Reputation points

    please check this video

    for example:

    Image embeddedImage = new Image
        Source = ImageSource.FromResource("WorkingWithImages.beach.jpg", typeof(MyClass).GetTypeInfo().Assembly)
    0 comments No comments