Anpeiron
Anpeiron

Reputation: 43

LoadImageFromUrl IBitmap to ImageSource

I am using the code below the Akavache to cache images.

Return is an IBitmap, how can I convert this IBitmap to an ImageSource?

var url = "https://ashdbhjas/image.png";
ImageSource imageSrc = await BlobCache.LocalMachine.LoadImageFromUrl(url); // ???

Upvotes: 2

Views: 309

Answers (1)

pinedax
pinedax

Reputation: 9356

Try this:

var url = "https://ashdbhjas/image.png";
var img = await BlobCache.LocalMachine.LoadImageFromUrl(url); 

MemoryStream imageStream = new MemoryStream();

await img.Save(CompressedBitmapFormat.Jpeg, 1.0f, imageStream);

stream.Position = 0;
var imageSrc = ImageSource.FromStream(() => imageStream);

Basically you are saving the IBitmap into a MemoryStream then using this to create your ImageSource object of your Image.

Hope this helps!

Upvotes: 3

Related Questions