【发布时间】:2017-07-11 02:47:59
【问题描述】:
当我在裁剪后存储从相机捕获的图像时,裁剪后的 jpg 图像文件是
存储在我指定的文件夹中。
我想存储带有 bmp 文件扩展名的“那个”裁剪图像文件。
【问题讨论】:
-
如果一个帖子解决了你的问题,请标记为答案,这是礼貌的方式。
当我在裁剪后存储从相机捕获的图像时,裁剪后的 jpg 图像文件是
存储在我指定的文件夹中。
我想存储带有 bmp 文件扩展名的“那个”裁剪图像文件。
【问题讨论】:
我建议的步骤是:
裁剪后的 jpg 使用此代码将其转换为位图
Bitmap bMap = BitmapFactory.decodeFile(imgPath);
使用 bmp 扩展保存 bMap,您可以通过 HERE 遵循建议功能
删除裁剪的 jpg 文件以释放内存
File dir = getFilesDir();
File file = new File(dir, "filename");
if (file.exists()) {
boolean deleted = file.delete();
}
【讨论】:
试试下面的代码 -
FileOutputStream out = null;
try {
out = new FileOutputStream(AbsoluteFilePath);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
// PNG is a lossless format, the compression factor (100) is ignored
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
【讨论】: