2

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); // ???
Anpeiron
  • 43
  • 1
  • 6

1 Answers1

3

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!

Mark
  • 7,891
  • 5
  • 27
  • 36
pinedax
  • 9,246
  • 2
  • 23
  • 30