Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to load a simple image as a background for a GPS app using C# in Visual Studio.

The resources are located in

Resources/drawable/resource file

Now I've been trying to display these files like this, "Arrow" en "Map"

Kaart = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.Map, opt);

Pijl = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.Arrow, opt);

I've declared "Kaart" and "Pijl" als bitmaps at the start of the class but "Map" and "Arrow" remain unrecognised and are red underlined saying that Resource.Drawable does not contain a definition for "Arrow" and "Map".

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
218 views
Welcome To Ask or Share your Answers For Others

1 Answer

Resources res = getContext().getResources();
int id = R.drawable.image; 
Bitmap b = BitmapFactory.decodeResource(res, id);

This shall return the decoded Bitmap or it will return null if the image cannot be decoded.

NOTE : The Bitmap would be different if "image" exists in all drawable folders(like ldpi,mdpi,hdpi , etc) . So it's ideal to keep the image in the original drawable folder unaltered.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...