Here is My Code the way I’m creating my folder in app Specific directory.
private File createDirectory(String dirName) {
File file = new File(getApplicationContext().getExternalFilesDir(dirName) + "/" + dirName);
if (!file.exists()) {
file.mkdir();
}
return file;
}
3
Answers
your method returns
File
, which is a directory. now you have to create new image file objectnow you have to compress your
Bitmap
as JPG (as name set above) and feed this streamand don’t foregt to close stream
if you want lossless format you can use PNG (
Bitmap.CompressFormat.PNG
), don’t forget to name your file extension accordinglyyou can only write in your
app-specific
filesyou can use the function "getExternalFilesDir" and you change the value between in parenthesis. Here I put "Environment.DIRECTORY8DCIM" but there are others (you can check in the android developer web site).
I show you an exemple:
Hope that work for you 🙂