Mono Droid – Load Image Resource from Web

Alright – so you need to load an image dynamically as part of your Android Layout. You would think you can do this:


But that won’t work. What happens? I’ll tell you. You end up with an error in the log that says:

Resolve Uri failed on bad bitmap Uri

This is because it is looking to resolve the Uri locally. So if your image is sitting at arms length (ie, on your SDcard or somewhere on the file system) then you need to work on getting that string to look right (there are plenty of google results on resolving this issue). But if you want to load it from a remote location (so you can change it without having to push out a new version of your app)

Change that line above to this:

var bm = BitmapFactory.DecodeStream(
        new Java.Net.URL("").OpenStream());

So hopefully this helps someone load an image they need loaded dynamically in their Android App that is in Mono Droid. There are some other complicated ways to load an image using byte arrays and stuff but why do all that when you can get the bitmap loaded with this method. I’d recommend only doing this with small images though – might start to run into threading issues and timing issues if you try to load big files from a remote location.