手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android中知道图片name时获取图片的简单方法
android中知道图片name时获取图片的简单方法
摘要:1.图片放在sdcard中,复制代码代码如下:BitmapimageBitmap=BitmapFactory.decodeFile(path...

1. 图片放在sdcard中,

复制代码 代码如下:

Bitmap imageBitmap = BitmapFactory.decodeFile(path) (path 是图片的路径,跟目录是/sdcard)

2. 图片在项目的res文件夹下面

复制代码 代码如下:

//得到application对象

ApplicationInfo appInfo = getApplicationInfo();

//得到该图片的id(name 是该图片的名字,"drawable" 是该图片存放的目录,appInfo.packageName是应用程序的包)

int resID = getResources().getIdentifier(name, "drawable", appInfo.packageName);

3. 图片放在src目录下

复制代码 代码如下:

String path = "com/timanetworks/jerome/activity/test.png"; //图片存放的路径

InputStream is = getClassLoader().getResourceAsStream(path); //得到图片流

【android中知道图片name时获取图片的简单方法】相关文章:

Android中使用sax解析xml文件的方法

Android中 动态改变对话框值的方法

android获取监听SD Card状态的方法

Android Intent启动别的应用实现方法

Android中将一个图片切割成多个图片的实现方法

Android实现图片循环播放的实例方法

android apk反编译到java源码的实现方法

Android中使用Gson解析JSON数据的两种方法

android中实现指针滑动的动态效果方法

android实现字体闪烁动画的方法

精品推荐
分类导航