I have a bitmap that I want to save it to the app folder. I try with these codes:
ContextWrapper contextWrapper = new ContextWrapper(context.getApplicationContext());
File directory = contextWrapper.getDir("tabs", Context.MODE_PRIVATE);
if (!directory.exists())
directory.mkdir();
String fname = "Image.jpg";
File file = new File(directory, fname);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
fos.close();
} catch (Exception e) {
Log.e("SAVE_IMAGE", e.getMessage(), e);
}
Now, I have two problems.
Result of 'File.mkdir()' is ignored
You can just do this:
try {
FileOutputStream fileOutputStream = context.openFileOutput("Your File Name", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
It saves your bitmap in the "files" directory in app folder.
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/tabs";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
File futureStudioIconFile = new File(path, "Image.jpg);
if (futureStudioIconFile.exists())
futureStudioIconFile.delete();
futureStudioIconFile.createNewFile();
try this ,, i wish it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With