返回结果时我有位图图像,然后我想将其保存在 SD 卡的 Photo Art Camera 文件夹中,但未保存。它显示吐司“照片未成功保存”。
这是代码:
mSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
File cacheDir;
Bitmap bitmap = result;
// String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
Date d = new Date();
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
cacheDir = new File(android.os.Environment.getExternalStorageDirectory(), "Photo Art Camera");
} else { cacheDir = MainActivity.this.getCacheDir(); }
if (!cacheDir.exists()) { cacheDir.mkdirs(); }
File file = new File(cacheDir, "PhotoMarge" + d.getTime() + ".jpg");
try {
fOut = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 150, fOut);
// getImageBitmap(myurl).compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
Toast.makeText(MainActivity.this, "Photo Saved Sucessfully", 500).show();
// mDialog.dismiss();
// MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
}
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (Exception e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Photo Not Saved Sucessfully", 500).show();
}
}
});