Forum Xamarin.Forms

skiasharp - get SKBitmap from URL

trishelwoodtrishelwood USMember ✭✭

Hello,

Can I know how can I get SKBitmap from URL ?

I tried like this but i didn't get it. It is null.

var bitmap = SKBitmap.Decode(url);

Thanks !!!

Answers

  • mattleibowmattleibow ZAXamarin Team Xamurai

    SkiaSharp does not do any network operations, but this can be done in a few lines of code:

    // download the bytes
    var httpClient = new System.Net.Http.HttpClient();
    var bytes = await httpClient.GetByteArrayAsync(url);
    
    // wrap the bytes in a stream
    var stream = new MemoryStream(bytes);
    
    // decode the bitmap stream
    var bitmap = SKBitmap.Decode(stream);
    
  • NickKovalskyNickKovalsky USMember ✭✭✭

    Even more you can use FFImageLoading nuget for faster cached images:

                    var stream = await ImageService.Instance.LoadUrl(url).AsJPGStreamAsync();
                    var bitmap= SKBitmap.Decode(stream);
    
Sign In or Register to comment.