0

I am retrieving a set of images of a server and the images are stored in string form. How I'm doing this is:

String imageString = jObject.GetString("Image");
byte[] imageAsBytes = Base64.Decode(imageString, Base64Flags.Default);
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, 
imageAsBytes.Length);
ProcImage.SetImageBitmap(bitmap);
bitmap = null;

This is apparently very slow. The screens that have a lot of images needing to be retrieved have an 8 second load time.

As a result, I was wondering if I could do the "DecodeByteArray()" asynchronously somehow, as this is what takes the most time.

I know it is possible, but I am unsure of how to approach this as I am fairly new to Android and Xamarin

1 Answer 1

1

So if I understand you correctly you want to do the decoding in the background? If so you can start a background task with:

     Task.Run(() =>
        {
          //Code here
        });

edit It seems you more interested in making the image load faster in your application. I would suggest taking a look at: https://forums.xamarin.com/discussion/58341/ffimageloading-plugin-fast-and-memory-friendly-image-loader-ios-android-forms-windows

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

8 Comments

This displays the image like I need it to, but do you think that loading the images in the background will improve my load time at all?
It will improve the load time of your next page, but your images won't be decoded faster. I use this task to upload my pictures to my servers since I do want the user to wait till the end
The reason I ask is, the process of retrieving the images from the server is taking almost 8 seconds on the device I'm testing it on. I was just trying to do anything to make that number lower ~
I'm confused why you asked for a async solution than, if I understand you correctly you want a faster way of getting the images from you server and converting them? A background task is no option since the user needs to see the images instantly?
the only issue is that this plugin helps make instant loading faster when it is from a stream, a url, or a file.I am retrieving a string and have to decode it that way
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.