2

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

1

1 Answer 1

2

You can use LoadStream method, here you will see how to use this method:

ImageService.Instance .LoadStream (GetStreamFromImageByte) .Into (imageView); 

Here is the 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; } 

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(); 

I have posted my demo on github.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.