android读取图片
来源:互联网 发布:流星网络电视apk安卓 编辑:程序博客网 时间:2024/05/18 18:16
一:读取res中的图片
//读取本地res中的图片public static Bitmap readBitmap(int resid){
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
//获取资源图片
InputStream input = getResources().openRawResource(resid);
return BitmapFactory.decodeStream(input,null,opt);
}
//确定不再需要该bitmap对象的时候可以将其回收掉
public static void recycle(Bitmap bitmap){
if(bitmap!=null && !bitmap.isRecycle()){
bitmap.recycle();
System.gc();//提醒系统及时回收
}
}
二:放在assets中的图片(只读)
InputStream is = context.getResources().getAssets().open("icon.png");
Bitmap bitmap = BitmapFactory.decodeStream(is);
三:读取sd卡中的图片
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/icon.png");
四:读取网络图片
public static Bitmap loadImageFromUrl(String urlStr){
URL url;
InputStream i = null;
try{
m = new URL(urlStr);
i = m.getContent();
}catch(Exception e){
e.printStaceTrace();
}
return BitmapFactory.decodeStream(i);
}
- android读取网络图片
- android读取图片
- android读取图片
- android读取图片
- android读取网络图片
- android读取图片
- Android读取网络图片
- Android 图片文件读取
- Android读取服务器图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- Android 读取Assets中图片
- android读取远程图片案例
- 读取图片 优化android内存
- android Bitmap 读取缩放图片
- Android 读取Assets中图片
- Android 读取图片方向信息
- 内存管理之内存池的设计
- 黑马程序员_java编程基础02
- Java 中的 jndi
- POJ3006-Dirichlet's Theorem on Arithmetic Progressions解题报告
- 晨间日记
- android读取图片
- 解决安装 Mono for Android for VS2010 后出现 “get_AdbExe()”的异常
- poj-3259-Wormholes
- hadoop 任务超时自动结束任务
- onvif与directshow 2
- ACE自适配通信环境(ADAPTIVE Communication Environment)
- 二十七、Java图形化界面设计——容器(JFrame)
- 图片切换 及 关于 CATransition的动画效果类型
- 解决因浏览器缓存不刷新网页的问题