【发布时间】:2017-10-27 09:19:24
【问题描述】:
我正在使用一个应用程序来获取 gps 位置并将其绘制为位图上的一个圆圈,然后将其保存以继续,因此我需要反复读取和保存文件。但不幸的是,当我保存文件并阅读它时,经过一些迭代,文件已损坏......!
代码:
File output = new File(tmpDirectory, "map.jpg");
try {
OutputStream outputStream = new FileOutputStream(output);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.flush();
outputStream.close();
} catch (Exception ex) {
Message("error!");
}
directory = tmpDirectory;//updating directory to load the manipulated image
readFile(directory + "map.jpg", false);//setting the image view new image
图片包括:picture after iterations 图片包括: main image
【问题讨论】:
-
“我正在使用应用程序获取 gps 位置并将其绘制为位图上的圆圈,然后保存以继续,因此我需要重复读取和保存文件”- 为什么要您需要“反复读取和保存文件”吗?您已经拥有
Bitmap。您无需再次阅读即可使用Bitmap。
标签: android bitmap jpeg outputstream image-compression