嗨,我正在制作一个允许用户在屏幕上绘图的 Android 应用程序。我有一个按钮,按下时我希望画布作为图像保存到内部存储器中。我尝试了以下代码,但我不断收到FileNotFoundException open failed: EACCES (permission denied)
:
String path = Environment.getDataDirectory().getAbsolutePath();
File file = new File(path+"image.png");
Bitmap bitmap = Bitmap.createBitmap(100,200,Bitmap.Config.ARGB_8888);
FileOutputStream ostream;
try {
ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
e.printStackTrace();
}