如何在Xamarin Android Native上将位图加载到ImageViewAsync?
答案 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上发布了我的演示。