Home

Awesome

glidex.forms (or just glidex)

Google recommends Glide for simplifying the complexity of managing Android.Graphics.Bitmap within your apps (docs here).

glidex.forms is small library we can use to improve Xamarin.Forms image performance on Android by taking a dependency on Glide. See my post on the topic here.

Download from NuGet:

glidex.forms
NuGet

Learn more on this episode of the Xamarin Show:

Super Fast Image Loading for Android Apps with GlideX | The Xamarin Show

If you have a "classic" Xamarin.Android app that is not Xamarin.Forms, it could be useful to use the Xamarin.Android.Glide NuGet package. If you want to improve the Xamarin binding for Glide, contribute to it on Github!

How do I use glidex.forms?

To set this library up in your existing project, merely:

Xamarin.Forms.Forms.Init (this, bundle);
//This forces the custom renderers to be used
Android.Glide.Forms.Init (this);
LoadApplication (new App ());

How do I know my app is using Glide?

On first use, you may want to enable debug logging:

Android.Glide.Forms.Init (this, debug: true);

glidex.forms will print out log messages in your device log as to what is happening under the hood.

If you want to customize how Glide is used in your app, currently your option is to implement your own IImageViewHandler. See the GlideExtensions class for details.

Comparing Performance

It turns out it is quite difficult to measure performance improvements specifically for images in Xamarin.Forms. Due to the asynchronous nature of how images load, I've yet to figure out good points at which to clock times via a Stopwatch.

So instead, I found it much easier to measure memory usage. I wrote a quick class that runs a timer and calls the Android APIs to grab memory usage.

Here is a table of peak memory used via the different sample pages I've written:

NOTE: this was a past comparison with Xamarin.Forms 2.5.x

PageLoaded byPeak Memory Usage
GridPageXamarin.Forms268,387,112
GridPageglidex.forms16,484,584
ViewCellPageXamarin.Forms94,412,136
ViewCellPageglidex.forms12,698,112
ImageCellPageXamarin.Forms24,413,600
ImageCellPageglidex.forms9,977,272
HugeImagePageXamarin.Forms267,309,792
HugeImagePageglidex.forms9,943,184

NOTE: I believe these numbers are in bytes. I restarted the app (release mode) before recording the numbers for each page. Pages with ListViews I scrolled up and down a few times.

Stock XF performance of images is poor due to the amount of Android.Graphics.Bitmap instances created on each page. Disabling the Glide library in the sample app causes "out of memory" errors to happen as images load. You will see empty white squares where this occurs and get console output.

To try stock Xamarin.Forms behavior yourself, you can remove the references to glidex and glidex.forms in the glide.forms.sample project and comment out the Android.Glide.Forms.Init() line.

Features

In my samples, I tested the following types of images:

For example, the GridPage loads 400 images into a grid with a random combination of all of the above:

GridPage