将相机中的照片保存到 android 个内部存储器
save the photos from camera to android internal storage
我成功保存了来自android相机的照片
使用以下根路径
Environment.getExternalStorageDirectory()
和
context.getExternalFilesDir(null)
但我无法使用以下根路径保存
context.getFilesDir()
你知道是否可以将 android 相机拍摄的照片保存到 android 内部存储器,其中 context.getFilesDir()
作为根文件夹?
我使用以下代码启动相机:
Intent takePictureIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PICTURE);
//and this code I used to get the camera output
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode ==
Activity.RESULT_OK)
) {
Toast.makeText(this, "Can get the image.",
Toast.LENGTH_LONG).show();
//Bitmap photo = (Bitmap) data.getExtras().get("data");
// System.out.println("photo "+photo.getWidth());
// final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
// imageView.setImageBitmap(photo);
} else if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode == Activity.RESULT_CANCELED)) {
Toast.makeText(this, "Cannot get the image.", Toast.LENGTH_LONG).show();
}
}
您不能使用getFilesDir()
,因为您正在启动第三方相机应用来拍照,并且它无法写入您应用的内部存储。
我成功保存了来自android相机的照片 使用以下根路径
Environment.getExternalStorageDirectory()
和
context.getExternalFilesDir(null)
但我无法使用以下根路径保存
context.getFilesDir()
你知道是否可以将 android 相机拍摄的照片保存到 android 内部存储器,其中 context.getFilesDir()
作为根文件夹?
我使用以下代码启动相机:
Intent takePictureIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PICTURE);
//and this code I used to get the camera output
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode ==
Activity.RESULT_OK)
) {
Toast.makeText(this, "Can get the image.",
Toast.LENGTH_LONG).show();
//Bitmap photo = (Bitmap) data.getExtras().get("data");
// System.out.println("photo "+photo.getWidth());
// final ImageView imageView = (ImageView) findViewById(R.id.imageView1);
// imageView.setImageBitmap(photo);
} else if ((requestCode == REQUEST_TAKE_PICTURE) && (resultCode == Activity.RESULT_CANCELED)) {
Toast.makeText(this, "Cannot get the image.", Toast.LENGTH_LONG).show();
}
}
您不能使用getFilesDir()
,因为您正在启动第三方相机应用来拍照,并且它无法写入您应用的内部存储。