保存Bitmap到本地文件夹
2016-06-03 12:11
169 查看
[方法一]:
/** 保存方法 */
public void saveBitmap() {
Log.e(TAG, "保存图片");
File f = new File("/sdcard/namecard/", picName);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
Log.i(TAG, "已经保存");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在这里还需要两个权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
[方法二]:
public void saveMyBitmap(String bitName, Bitmap mBitmap) throws IOException {
File f = new File("/sdcard/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/** 保存方法 */
public void saveBitmap() {
Log.e(TAG, "保存图片");
File f = new File("/sdcard/namecard/", picName);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
Log.i(TAG, "已经保存");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在这里还需要两个权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
[方法二]:
public void saveMyBitmap(String bitName, Bitmap mBitmap) throws IOException {
File f = new File("/sdcard/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
相关文章推荐
- iOS通过CIFilter对图像进行滤镜处理
- 利用System.IO.Compression操作压缩文件
- 利用蒲公英发布内测版本APP
- GitHub 删除指定仓库
- 20150414二维数组
- jxl导入导出Excel
- Linux查看Nginx或者其他程序的安装目录
- ASIHTTPRequest介绍
- iOS开发手机号判断(截止到2016年5月的所有号段)
- 【笔记】Yii2 - Gii使用:Module Generator
- TCP Provider The semaphore timeout period has expired
- ubuntu 15.10 更改设备网卡名称为eth0 网卡
- 类的定义和实例化
- Eclipse下用javadoc导出Android项目的帮助文档
- 强大的命令行工具wmic
- centos环境下配置多个版本的mysql
- Binary Tree Paths
- 平面扫描思想在ACM竞赛中的应用(转载)
- linux下supervisord的简单使用
- 关于判断输入框为空和出入空格的方法