如何使用 Xamarin 的 FFImageLoading 加载本地存储在字节数组中的图像? [英] How do load a image stored locally in byte array using FFImageLoading for Xamarin?
问题描述
我需要能够使用 FFImageLoading.ImageService
将我之前从图像解码的字节数组加载到 FFImageLoading.Views.ImageViewAsync
对象中.方法 ImageService.Instance.LoadImage(IImageLoaderTask task)
似乎是方法,但我不知道如何设置该接口的对象,我找不到使用此类型对象的任何引用在源网站上.
I need to be able use FFImageLoading.ImageService
to load a byte array I decoded from an image earlier, into a FFImageLoading.Views.ImageViewAsync
object. The method ImageService.Instance.LoadImage(IImageLoaderTask task)
seems to be the way but I have no idea how to set up an object of that interface and I can't find any references to using this type object on the source website.
如何将 byte[] 加载到 ImageViewAsync
对象中?
How to load a byte[] into a ImageViewAsync
object?
推荐答案
既然你已经有了一个 byte[],你可以用 LoadStream
方法来实现.
Since you already have a byte[] you could you this with the LoadStream
method.
类似于:
ImageService.Instance
.LoadStream (GetStreamFromImageByte)
.Into (imageView);
这就是做实际工作的方法.
And this is the method to do the actual work.
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;
}
这应该有效.
这篇关于如何使用 Xamarin 的 FFImageLoading 加载本地存储在字节数组中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!