Skip to content
glidex.forms is an attempt at using Glide for faster Xamarin.Forms images on Android. glidex is a Xamarin binding of Glide found at https://github.com/bumptech/glide
Branch: master
Clone or download
Latest commit 38988d9 Mar 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
glidex.forms.sample Remove obsolete Forms.Context. (#27) Mar 20, 2019
glidex.forms Use IActivityLifecycleCallbacks to remove static ref to Activity (#29) Mar 20, 2019
glidex.sample Remove $(AndroidUseLatestPlatformSdk) Mar 20, 2019
glidex Remove $(AndroidUseLatestPlatformSdk) Mar 20, 2019
tools Update Cake to 0.31.0 (#22) Dec 13, 2018
.editorconfig Add a .editorconfig file Mar 20, 2019
.gitattributes
.gitignore [build] NuGet push seems to work Mar 2, 2018
LICENSE
README.md
appveyor.yml
build.cake
build.ps1 Initial Cake/NuGet setup Mar 2, 2018
build.sh
glidex.sln
helpers.cake Update helpers.cake Oct 19, 2018

README.md

glidex and glidex.forms

glidex is a minimalist Xamarin.Android binding of Glide. Google recommends Glide for simplifying the complexity of managing Android.Graphics.Bitmap within your apps (docs here).

glidex.forms is a prototype of what we can do to improve Xamarin.Forms image performance on Android by taking a dependency on Glide. See my post on the topic here.

Download from NuGet (use the Prerelease checkbox):

glidex glidex.forms
NuGet NuGet

Learn more on this episode of the Xamarin Show:

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

We don't want or care to bind the entirety of Glide's public API surface. Our goal here is to just bind the "useful" APIs for Glide.

For example take the following C#:

var image = FindViewById<ImageView> (Resource.Id.testImage);
Glide.With (this)
    .Load ("https://botlist.co/system/BotList/Bot/logos/000/002/271/medium/chuck_norris.jpg")
    .Apply (RequestOptions.CircleCropTransform ().Placeholder (Android.Resource.Drawable.IcMenuCamera))
    .Into (image);

This code loads an image from a URL dynamically, taking care of all of Glide's cool caching functionality. These are the only APIs we need to make the library useful.

If you have a "classic" Xamarin.Android app that is not Xamarin.Forms, it could be useful to use the glidex NuGet package directly.

glidex is currently using the 4.7.0 release of Glide from Github

glidex.forms for Xamarin.Forms on Android

My goal with this repo is to get fast Images for Xamarin.Forms on Android by using Glide.

The new IImageViewHandler API in Xamarin.Forms 3.3.x, allows glidex.forms to operate without using any custom renderers!

But to set this library up in your existing project, merely:

  • Add the glidex.forms NuGet package
  • Add this one liner after your app's Forms.Init call:
Xamarin.Forms.Forms.Init (this, bundle);
//This forces the custom renderers to be used
Android.Glide.Forms.Init ();
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 (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

Page Loaded by Peak Memory Usage
GridPage Xamarin.Forms 268,387,112
GridPage glidex.forms 16,484,584
ViewCellPage Xamarin.Forms 94,412,136
ViewCellPage glidex.forms 12,698,112
ImageCellPage Xamarin.Forms 24,413,600
ImageCellPage glidex.forms 9,977,272
HugeImagePage Xamarin.Forms 267,309,792
HugeImagePage glidex.forms 9,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:

  • ImageSource.FromFile with a temp file
  • ImageSource.FromFile with AndroidResource
  • ImageSource.FromResource with EmbeddedResource
  • ImageSource.FromUri with web URLs
  • ImageSource.FromStream with AndroidAsset

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

GridPage

You can’t perform that action at this time.