Created
December 21, 2017 15:21
-
-
Save linhdh/56ec67e269aabf908afd29c48a77bfad to your computer and use it in GitHub Desktop.
[Xamarin, Android] Get Bitmap from filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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