2017-05-26 102 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);