I am building an Android app and of its jobs is to save a picture out of a canvas. The screenshoting part works great, the problem is when I save the photo. When I try to look at the photo the app saved, I get a black screen.
My code for saving is:
private int saveToInternalStorage(Bitmap bitmapImage) {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOutputStream = null;
File file = new File(path + "/drawings/");
if (!file.exists()) {
file.mkdirs();
}
file = new File(path + "/drawings/", "drawing.png");
try {
fOutputStream = new FileOutputStream(file);
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fOutputStream);
fOutputStream.flush();
fOutputStream.close();
MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
return 0;
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Save Failed, Error 1", Toast.LENGTH_SHORT).show();
return -1;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Save Failed, Error 2", Toast.LENGTH_SHORT).show();
return -1;
}
}
Plus, the photo doesn't appear in my gallery.
What can I do in order to solve this?
Thanks, Iliya.