Alexey Vukolov
Alexey Vukolov

Reputation: 223

Convert android drawable into xamarin.forms ImageSource

I have an API binded to Xamarin.Android part of project, that returns image as Drawable object. I need to show this image in UI, that is written in Xamarin.Forms. The problem is that Image control there accepts only ImageSource as a source. How can I wrap Drawable into ImageSource object?

Upvotes: 2

Views: 1068

Answers (1)

Daniel
Daniel

Reputation: 1545

You can do like this:

byte[] bytes = drawable.ToArray();
var iamgeSource = ImageSource.FromStream(() => new MemoryStream(bytes));

Upvotes: 1

Related Questions