[英]How to store image captured from camera in gallery?
我想将从图像中捕获的图像存储在图库中。 我不希望它们存储在sdcard上。 如何实现。 我有以下代码
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
startActivityForResult(i, CHOOSE_CAMERA_RESULT);
tempuri
应该是tempuri
?
tempuri=Uri.fromFile(getOutputFromCamera());
getOutputFromCamera()在哪里
private File getOutputFromCamera() {
File storageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
AppConstants.FOLDER_NAME);
if (!storageDir.exists()) {
if (!storageDir.mkdirs()) {
Log.i(TAG, "Failed to create directory " + storageDir
+ AppConstants.FOLDER_NAME);
Toast.makeText(this, "Failed to create Directory",
Toast.LENGTH_SHORT).show();
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File imageFile = new File(storageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".png");
return imageFile;
}
其中Environment.DIRECTORY_PICTURES是默认图片目录, AppConstants.FOLDER_NAME是保存图像的文件夹名称。 您可以根据需要进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.