Skip to content Skip to sidebar Skip to footer

Ffimageloading Load Bitmap Into Imageviewasync

How can I load a bitmap into an ImageViewAsync on Xamarin Android Native?

Solution 1:

You can use LoadStream method, here you will see how to use this method:

ImageService.Instance.LoadStream (GetStreamFromImageByte)
            .Into (imageView);

Here is the GetStreamFromImageByte:

Task<Stream> GetStreamFromImageByte (CancellationToken ct)
{
    //Here you set your bytes[] (image)byte [] imageInBytes = null;

    //Since we need to return a Task<Stream> we will use a TaskCompletionSource>
    TaskCompletionSource<Stream> tcs = new TaskCompletionSource<Stream> ();

    tcs.TrySetResult (new MemoryStream (imageInBytes));

    return tcs.Task;
}

About imageInBytes, you can look here, convert the bitmap to byte[]:

MemoryStreamstream=newMemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
byte[] bitmapData = stream.ToArray();

I have posted my demo on github.

Post a Comment for "Ffimageloading Load Bitmap Into Imageviewasync"