Answer the question
In order to leave comments, you need to log in
How to save bitmap to file?
Hello.
I'm trying to save a bitmap to a file using this code:
Bitmap bmp1 = Bitmap.createBitmap(result.cols(), result.rows(), Bitmap.Config.ARGB_8888);
File file = new File(context.getFilesDir(), "imageStitched.png");
System.out.println("-------======= "+ context.getFilesDir() +" =======-------");
try {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bmp1.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} finally {
if (fos != null) fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
I don't know how in Android, but in a normal file system, I would first check if the specified directory exists with a full path (without a file name). And if it doesn't exist, then I would create it, if there are rights. For our case it will be like this:
if ( !file.getParentFile().exists())
{
java.nio.file.Files.createDirectory( file.getParentFile().toPath() );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question