rchau
rchau

Reputation: 535

Removing background of a transparent image in Xamarin Forms?

I am simply displaying an Image on my Xamarin Forms page. The image is transparent and this is how it displaying on page:

enter image description here

How can I remove those white and grey background? This is my source code:

<ContentPage.Content>
        <StackLayout>
            <Image x:Name="myimage" Aspect="Fill">
            </Image>
        </StackLayout>
 </ContentPage.Content>

Code-behind

myimage.Source = ImageSource.FromResource("RailwayApp.bull.jpg");

My try: I tried setting IsOpaque property to True/False neither worked. Also declared BackgroundColor="Transparent" on XAML page but not worked.

Upvotes: 1

Views: 3273

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39102

In this case you can't, the background is actually not transparent - it would have to be a transparent PNG or GIF to support this. This is a JPG, so the background is actually grey and white.

To make this work you will first have to actually make the image transparent by converting in one of the two transparent formats (and actually remove the background) and then it should display as transparent as expected.

Upvotes: 3

Related Questions