Skip to content

Instantly share code, notes, and snippets.

@linhdh
Created December 21, 2017 15:21
Show Gist options
  • Save linhdh/56ec67e269aabf908afd29c48a77bfad to your computer and use it in GitHub Desktop.
Save linhdh/56ec67e269aabf908afd29c48a77bfad to your computer and use it in GitHub Desktop.
[Xamarin, Android] Get Bitmap from filename
string imagefileName = "testimage.jpg";
// Remove the file extention from the image filename
imagefileName = imagefileName.Replace(".jpg","").Replace(".png","");
// Retrieving the local Resource ID from the name
int id = (int)typeof(Resource.Drawable).GetField(imagefileName).GetValue(null);
// Converting Drawable Resource to Bitmap
var myImage = BitmapFactory.DecodeResource(Forms.Context.Resources, id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment