FFImageLoading 加载位图到 ImageViewAsync

FFImageLoading load bitmap into ImageViewAsync

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

你可以使用LoadStream method, 你会看到如何使用这个方法:

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 上发布了我的演示。