FFImageLoading将位图加载到ImageViewAsync中 [英] FFImageLoading load bitmap into ImageViewAsync

查看:89
本文介绍了FFImageLoading将位图加载到ImageViewAsync中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

You can use LoadStream method, here you will see how to use this 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 ,您可以在此处,转换位图代码>到 byte [] :

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

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

我已经在 github 上发布了我的演示.

I have posted my demo on github.

这篇关于FFImageLoading将位图加载到ImageViewAsync中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆