Android中图片转化为bitmap
2016-01-26 09:41
471 查看
图片文件和Bitmap之间的转换
图片文件转为Bitmap对象String filePath="c:/01.jpg";
Bitmap bitmap=BitmapFactory.decodeFile(filePath);
如果图片过大,可能导致Bitmap对象装不下图片
解决办法:
String filePath="c:/01.jpg";
Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2));
//将图片的长和宽缩小味原来的1/2
private BitmapFactory. Options getBitmapOption(int inSampleSize){
System.gc();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
options.inSampleSize = inSampleSize;
return options;
}
Bitmap对象保存味图片文件
public void saveBitmapFile(Bitmap bitmap){
File file=new File("/mnt/sdcard/pic/01.jpg");//将要保存图片的路径
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
相关文章推荐
- 安卓常用adb命令
- android新技术学习(1)-2016年,这些Android技术会很火
- Android-带有切换动画的CheckBox
- 如何在mac本上安装android sdk
- 关于android 和 耗时操作的一点理解
- android中信息列表的下拉刷新和下拉加载
- Android开发优化之——使用软引用和弱引用
- Android5.0适配——水波纹点击效果
- Android中ListView下拉刷新的实现
- Android 拷贝raw文件夹下面的sqlite数据库文件到SDCard中 然后读取数据库并绑定
- Androidx学习笔记(25)-- 单选对话框
- Androidx学习笔记(24)--对话框
- Androidx学习笔记(24)-- ArrayAdapter&SimpleAdapter
- android发编译
- Androidx学习笔记(23)-- 创建ListView展示数据库的数据
- Android——Widget实现
- android开发开机自启动功能
- Android开发之getMeasuredWidth和getWidth区别从源码分析
- Android事件分发机制--ViewGroup(二)
- Android事件分发机制——View(一)