Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

android - BitmapFactory.DecodeResource does not recognise drawables

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

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

1 Reply

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...