When I save a bitmap with this function, I get an unreadable file, bigger than the original image(using Root explorer on my phone) what is wrong? The bitmap is set by the user using the stock image picker.
Here is the call:
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
saveToInternalSorage(bitmap);
Here the saveToInternalSorage method (from here Saving and Reading Bitmaps/Images from Internal memory in Android )
private String saveToInternalSorage(Bitmap bitmapImage){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
String filename = randomString();
System.out.println(filename);
File mypath=new File(directory,filename);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return directory.getAbsolutePath();
}