开发者

How can I load an image from drawable folder?

I've the file name of an image stored in the drawable? how can I open it? I want to know the path?

the file name is String imageFileName = "image.png"

and I want to have the path string something li开发者_运维技巧ke file://drawable/image.png


You can open it using openRawResource(). See more at the documentation.

See this post regarding how to construct a uri to raw resource, though as far as I know it is not recommended.


You can access it through its resource ID. See previous answers such as this one: Select Drawable file path


Here is the code segment showing how you can refer to an image through its resource ID.

Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),
   R.drawable.pic1);
int pic_width  = mBitmap.width();
int pic_height = mBitmap.height();

See here for more detail

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜