目前,这样做只会将其存储到图库中。我不知道如何将裁剪的照片保存到我自己的文件夹中。
我的问题是:
如何将文件保存到我的本地文件夹?
case CROP_FROM_CAMERA:
Bundle extras = data.getExtras();
Bitmap photo = null;
if (extras != null) {
photo = extras.getParcelable("data");
mImageView.setImageBitmap(photo);
}
// Create new folder inside Palm Detect directory
File mediaStorageDir2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Palm Detect",
"Cropped Image");
// Create the storage directory if it does not exist
if (!mediaStorageDir2.exists()) {
if (!mediaStorageDir2.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ "Cropped Image" + " directory");
}
}
// Store cropped photo into gallery
Images.Media.insertImage(getContentResolver(), photo, "Img_" + String.valueOf(System.currentTimeMillis()), "");
break;
答案 0 :(得分:2)
您需要通过执行此操作添加本地文件
try {
mediaStorageDir2.createNewFile();
FileOutputStream ostream = new FileOutputStream(mediaStorageDir2);
photo.compress(CompressFormat.PNG, 10, ostream);
ostream.flush();
ostream.close();
System.gc();
} catch (Exception e) {
e.printStackTrace();
}
修改:您还需要为AndroidManifest.xml添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>