1
我在外部存儲器上有100個圖像,我在for循環中執行了以下兩個任務。在android中改善文件保存性能
- 加載的每個項目爲位圖,並在內存中
而對於100倍的圖像需要花費太多的時間與另一個位圖合併它
這是我如何合併位圖: how to merge to two bitmap one over another
我這是怎麼保存的位圖到文件:
File imageFileFolder = new File(Statics.TEMP_PATH);
imageFileFolder.mkdirs();
FileOutputStream out = null;
File imageFileName = new File(imageFileFolder, imageName);
try {
out = new FileOutputStream(imageFileName);
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
注意,所有這些都是在一個塊的AsyncTask。
你可以嘗試添加一個緩衝區,即'out = new BufferedOutputStream(new FileOutputStream(imageFileName),8 * 1024);'(嘗試更大的尺寸)有任何可測量的效果。 – zapl
太多時間了?請告訴幾秒鐘。同時告訴文件大小。使用cpu的核心並使用線程。每個核心都有一個線程。或者兩個。 – greenapps
@greenapps保存文件是一項昂貴的任務。如果你有任何解決方案,請告訴我,我會告訴你的差異。因爲數據集不是很重要。 – Aerox