简体   繁体   English

将位图保存到SD卡时出现FileNotFoundException

[英]FileNotFoundException when saving bitmap onto SD card

I tried to save "viewBitmap" into SD card. 我试图将“ viewBitmap”保存到SD卡中。

Here is my code: 这是我的代码:

try{
String mPath = Environment.getExternalStorageDirectory().toString();
imageFile = new File(mPath, "/snapshot.png");
FileOutputStream outputStream = new FileOutputStream(imageFile);
viewBitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream);
outputStream.flush();
outputStream.close();
Toast.makeText(Share.this, "Collage was saved.",Toast.LENGTH_SHORT).show();
}catch(Throwable e) {
 e.printStackTrace();
}

At the line "FileOutputStream outputStream = new FileOutputStream(imageFile);", an exception was thrown: 在“ FileOutputStream outputStream = new FileOutputStream(imageFile);”行中,引发了一个异常:

在此处输入图片说明

In your AndroidManifest.XML file did you add permission 您在AndroidManifest.XML文件中添加了权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, refer to the documentation to request the permission at run time. 如果设备运行的是Android 6.0(API级别23)或更高版本,并且应用程序的targetSdkVersion为23或更高版本,请参阅文档以在运行时请求权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM