FFImageLoading将位图加载到ImageViewAsync中

时间:2018-04-21 18:44:18

标签: xamarin xamarin.android android-bitmap ffimageloading

如何在Xamarin Android Native上将位图加载到ImageViewAsync?

1 个答案:

答案 0 :(得分:2)

您可以使用LoadStream方法,here您将看到如何使用此方法:

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

以下是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;
}

关于imageInBytes,您可以查看here,将bitmap转换为byte[]

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

我已在github上发布了我的演示。