转载:http://blog.csdn.net/zhoujiyu123/article/details/7343638
近日做到从内存卡读取图片的功能,在此,对获取图片资源的方法稍作总结:
方式一:
已将图片保存到drawable目录下,通过图片id获得Drawable或者Bitmap,此方式最常用。(若只知道图片的名称,还可以通过图片的名称获得图片的id)
(1)通过图片id获得Drawable
Drawable drawable=getResource().getDrawable(R.drawable.xxx);
(2)通过图片id获得Bitmap
Resource res=gerResource();
Bitmap bitmap=BitmapFactory.decodeResource(res, id);
(3)通过图片的名称获得图片的id(两种方法)
int id =res.getIdentifier(name, defType, defPackage); //name:图片的名,defType:资源类型(drawable,string。。。),defPackage:工程的包名
Drawable drawable=getResource().getDrawable(id);
方式二:
已将图片保存到assest目录下,知道图片的名称,通过inputstream获得图片Drawabl
或者 Bitmap
AssetManager asm=getAssetMg();
InputStream is=asm.open(name);//name:图片的名称
(1)获得Drawable
Drawable da = Drawable.createFromStream(is, null);
(2)获得Bitmap
Bitmap bitmap=BitmapFactory.decodeStream(is);
方式三: 图片保存在sdcard,通过图片的路径h
/图片路径
String imgFilePath = Environment.getExternalStorageDirectory().toString()
+ “/DCIM/device.png”;
(1)文件输入流
fis = new FileInputStream(new File(imgFilePath));//文件输入流
Bitmap bmp = BitmapFactory.decodeStream(fis);
(2)
ImageView iv = (ImageView) findViewById(R.id.image);
Bitmap bit = BitmapFactory.decodeFile("/sdcard/android.bmp");
iv.setImageBitmap(bit);
iv.setImageDrawable(Drawable.createFromPath(new File(Environment.getExternalStorageDirectory(), "camera.jpg").getAbsolutePath()));
分享到:
相关推荐
android 通过图片名称获取 drawable 目录下的图片 ~~~~~~~~~~~~~~~~~
android-gif-drawable 用于在Android上显示动画GIF
Android所有系统资源图标android.R.drawable.xxx查看软件 源码地址:http://blog.csdn.net/dianyueneo/article/details/7197067
查看android.R.drawable图片。点击并显示出名称 UTF-8 android2.2~android4.2
android_gif_drawable(播放gif图片)
android中的drawable集合,包括Bitmap、shape、Layer、Transition等等
Android-android-gif-drawable.zip,在android上显示动画gif的视图和绘图,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
android-gif-drawable Views and Drawable for animated GIFs in Android. Overview Bundled GIFLib via JNI is used to render frames. This way should be more efficient than WebView or Movie classes. ...
android-gif-drawable 开源组件,需要的朋友下载
Android系统图标android.R.drawable下的所有图标查看软件
参照github上android-gif-drawable框架出现的5.0不适配的问题。
Android应用源码之android-gif-drawable 支持fig显示的view.zip
github最新android-gif-drawable资源so; android-async-http-1.4.5.jar demo中实现了本地gif显示和网络加载gif显示
android-gif-drawable最快最流畅的GIF,带...不像很多其他资源,虽说用了android-gif-drawable的开源项目,但是没有编译so,也没有上传,你下载他的根本用不了!因此特意上传亲测可以直接使用的给大家!而且不要分!
Android高级应用源码-drawable(图片).zip
Android中不同类型的Drawable使用
开源库 android-gif-drawable使用的jar包,使用详见博客http://blog.csdn.net/u012587637/article/details/18596465
Android drawable 玩转自定义图片以及bug的解决
Drawable资源管理图片处理
android安卓APP之13种Drawable位图片资源.zip