I'm working with bitmap and have some problems need to help: My app works as below:
- Load JPG image file(1) from SDcard to bitmap1
- Save this bitmap1 to new JPG file(2).
- Load new JPG image(2) file to bitmap2
- Save bitmap2 to new JPG file(3) ....
- .... repeat again and again
Now I can load/save bitmap to file, but problem is quality of image reduces after load/save. So if I do load/save stuff for 10 times, so my image become ugly. This is my code:
private void saveBitmapToFile(String imgPath) {
Log.e("Filename-----------------", imgPath);
// Decode image file to bitmap
BitmapFactory.Options options = new BitmapFactory.Options();
// options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options);
// Get filename
long currentMili = System.currentTimeMillis();
currentName = currentMili + "";
String filePath = FOLDER_PATH + currentMili + ".jpg";
// Save bitmap to new file
try {
File file = new File(filePath);
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}