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
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
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments