Friday, September 5, 2014

Xamarin.Android Loading Images From the web

I recently decided to write an app and release it to the play store. The game is called Connect the Game and is available at or from the play store. I decided I was going to allow login with facebook and give the ability to invite facebook friends. However there was no facebook development kit that had a friend picker that I could just plug in. So I went to my friend google and found this post on Xamarin's website which points you to MonoDroid.UrlImageViewHelper. I attempted to use the Monodroid ViewHelper but it was too slow when trying to load up 500 facebook friend thumbnails. So I started pulling apart the code to find the bottleneck and I came up with a slimmed down version and it is fast. So without further ado the code.

If you wish to see how well this works you can try try the app. Login with your facebook account and then select new game. From the popup dialog touch Invite with facebook and watch the images load.

This is used to load thumbnails asynchronously. If you don't want to loose quality then change the call

bit.Compress(Bitmap.CompressFormat.Jpeg, 70, mstream);

to whatever fits your needs.

Image Helper Class

Facebook Friend Object

This is an object I created, you can create your own or modify this to make the class more generic. I only needed it for Facebook hence the non generic object

Putting them together in a List Adapter

No comments:

Post a Comment