Randy
Randy

Reputation: 1287

How do I set the Image source to something other than File in Xamarin?

I am trying to get my Button Image to display which is stored as a byte array in a sql server. I can set an image file which is stored on the device in the root directory on the UWP device.

    <Button x:Name="MyButton" Text="Test Me">
        <Button.Image>
            <FileImageSource File="Forward.png" />
        </Button.Image>
    </Button>

or

MyButton.Image = "Forward.png";

...works fine. I am trying to do Image.FromStream or something similar.

Upvotes: 0

Views: 32

Answers (1)

Wasif Mahmood Mustafa
Wasif Mahmood Mustafa

Reputation: 597

Retrieve the byte array from your database and pass it in this code.

 public static Image ConvertBinaryToImage(byte[] data)
    {
        using (MemoryStream ms = new MemoryStream(data))
        {
            return Image.FromStream(ms);
        }
    }

It will return the image and then you can bind it to your button.

Upvotes: 1

Related Questions