Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在gallery中存储从相机捕获的图像?_Java_Android_Android Camera_Gallery - Fatal编程技术网

Java 如何在gallery中存储从相机捕获的图像?

Java 如何在gallery中存储从相机捕获的图像?,java,android,android-camera,gallery,Java,Android,Android Camera,Gallery,我想在gallery中存储从图像捕获的图像。我不希望它们存储在SD卡上。如何做到这一点。我有以下代码 Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, tempuri); startActivityForResult(i, CHOOSE_CAMERA_RESULT); 什么应该是tempuri tempuri=Uri.fromFile(getOutputFro

我想在gallery中存储从图像捕获的图像。我不希望它们存储在SD卡上。如何做到这一点。我有以下代码

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

i.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
startActivityForResult(i, CHOOSE_CAMERA_RESULT);
什么应该是
tempuri

tempuri=Uri.fromFile(getOutputFromCamera());
getOutputFromCamera()的位置

其中,环境。目录\u图片是默认图片目录,AppConstants。文件夹\u名称是保存图像的文件夹名称。您可以根据需要更改这些

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;
}