Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded images not showing

This is my page in portable project

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:b="clr-namespace:Corcav.Behaviors;assembly=Corcav.Behaviors"
                 xmlns:local="clr-namespace:MyMobileApp;assembly=MyMobileApp"
                 x:Class="MyMobileApp.MainPage"
                 x:Name="MainPage">

      <Image Source="{local:ImageResource myimage.jpg}" />

This is my ImageResourceExtension in same portable project

namespace MyMobileApp
{
    [ContentProperty("Source")]
    public class ImageResourceExtension : IMarkupExtension
    {
        public string Source { get; set; }

        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Source == null)
                return null;

            var imageSource = ImageSource.FromResource(Source);

            return imageSource;
        }
    }
}

I have tried to add myimage.jpg as embedded in root of my project and in Resources folder, but no image is shown.

While debugging I see that the returned imageSource is of type Xamarin.Forms.StreamImageSource. How do I check if this is really found?

Can anyone spot the error here?

like image 300
Vili Avatar asked Nov 27 '15 07:11

Vili


People also ask

Why images are not displaying?

Possible causes. The web page is not pointing to the correct URL (location) of the image. The server or computer hosting the image has moved or removed the image, and the web page has not yet been updated. The web page or computer hosting the image is getting too many requests and can't send you the image.

Why can I not see the images on my website?

2: Enable the Option to Show All Images In this case, you can just launch Google Chrome and go to its Settings > Privacy and Security and select the 'Images' option under the 'Content' section. From here, you need to make sure that the option to show all images on your browser is enabled.

Why are my emails not showing images?

On your Android phone or tablet, open the Gmail app . your account. Under "Data usage," tap Images. Tap Always show.

How do I find embedded images in Outlook?

Step 1: Click Settings. Step 2: Click “View all Outlook settings.” Step 3: Click Mail > Layout. Step 4: Under the Sender image section, select “Show sender images.”


2 Answers

By default the image will have Build Action: None; this needs to be set to Build Action: EmbeddedResource. Right click on Image > properties > set [Build Action: EmbeddedResource] [enter image description here]1

like image 139
Osama AbuSitta Avatar answered Sep 19 '22 18:09

Osama AbuSitta


The correct XAML was to add the app name to the source.

<Image Source="{local:ImageResource MyMobileApp.myimage.jpg}" />
like image 36
Vili Avatar answered Sep 22 '22 18:09

Vili