android 保存bitmap到指定文件
16lz
2022-06-15
//保存bitmap到指定文件。
public static void saveBitmap(Bitmap bmp, String targetPath) {
File file = new File(targetPath);if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
saveBitmap(bmp, new FileOutputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
}
private static void saveBitmap(Bitmap bmp, FileOutputStream fos) {
try {
//80 is the compress quality
bmp.compress(Bitmap.CompressFormat.JPEG, 80, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
更多相关文章
- android的文件操作
- 更新android sdk出现 A folder failed to be renamed or moved
- Android(安卓)下实现带有图标和Checkbox的 ListView Item(2)
- 向SD卡写文件
- Android(安卓)Studio多环境打包
- [Android]解决failed to get the required ADT version from sdk
- Android简单文件浏览器源代码
- anroid 7.1添加自定义api服务
- NPM 和webpack 的基础使用