android 保存bitmap到指定文件
16lz
2021-01-23
//保存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利用TTF文件设置字体
- 向SD卡写文件
- android html 读写文件
- Android 播放MP4文件
- 【Android】如何实现一个简单的文件浏览器
- Android文件权限(Linux的权限)
- Android和IOS录制mp3语音文件的方法