我需要能够将FFImageLoading.ImageService
我之前从图像解码的字节数组加载到FFImageLoading.Views.ImageViewAsync
对象中。该方法ImageService.Instance.LoadImage(IImageLoaderTask task)
似乎是这种方式,但我不知道如何设置该接口的对象,并且在源网站上找不到使用此类型对象的任何引用。
如何将 byte[] 加载到ImageViewAsync
对象中?
我需要能够将FFImageLoading.ImageService
我之前从图像解码的字节数组加载到FFImageLoading.Views.ImageViewAsync
对象中。该方法ImageService.Instance.LoadImage(IImageLoaderTask task)
似乎是这种方式,但我不知道如何设置该接口的对象,并且在源网站上找不到使用此类型对象的任何引用。
如何将 byte[] 加载到ImageViewAsync
对象中?
就我而言,它是这样工作的......
模态.cs
public class User
{
public byte[] Avatar { get; set; }
}
视图模型.cs
public ImageSource Avatar
{
get
{
return ImageSource.FromStream(()=>
{
return new MemoryStream(this.User.Avatar);
});
}
}
查看.xaml
<ffimageloading:CachedImage x:Name="userAvatar"
Source = "{Binding Avatar}"
Grid.Column="0" Grid.Row="0" >
</ffimageloading:CachedImage>
由于您已经有一个 byte[] ,因此您可以使用该LoadStream
方法。
就像是:
ImageService.Instance
.LoadStream (GetStreamFromImageByte)
.Into (imageView);
这是做实际工作的方法。
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;
}
这应该有效。