2017-05-26 99 views
1

我正在使用应用程序获取gps位置,并将其绘制为位图上的圆圈,然后将其保存以继续,因此我需要重复读取并保存该文件。但不幸的是,当我保存文件并读取它时,文件在一些迭代之后被损坏......!
的代码:包括
bitmap.compress破坏图片质量

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

+1

“我使用一个应用程序来获取GPS位置,并绘制成一个位图一个圆,然后将其保存到前进,所以我需要重复读取和保存文件” - 为什么你需要到“重复读取和保存文件”?你已经有了'位图'。您不需要再次阅读它以使用该“位图”。 – CommonsWare

回答

1

JPEG使用有损压缩。这意味着每次迭代都会失去一些质量。如果你想保留它,你应该使用像PNG这样的无损格式。

bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);