Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Android 捕获的图像无法保存在设备上_Android_Image Capture - Fatal编程技术网

Android 捕获的图像无法保存在设备上

Android 捕获的图像无法保存在设备上,android,image-capture,Android,Image Capture,我正在尝试将相机拍摄的图像保存到设备上。但它并没有得到拯救 //---显示 <uses-permission android:name="ANDROID.PERMISSION.CAMERA" /> <uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE" /> 查看我在保存捕获图像的代码中所做的操作 /*************************** Camera Inten

我正在尝试将相机拍摄的图像保存到设备上。但它并没有得到拯救

//---显示

<uses-permission android:name="ANDROID.PERMISSION.CAMERA" />
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE" />

查看我在保存捕获图像的代码中所做的操作

/*************************** Camera Intent Start ************************/

            // Define the file-name to save photo taken by Camera activity

            String fileName = "Camera_Example.jpg";

            // Create parameters for Intent with filename

            ContentValues values = new ContentValues();

            values.put(MediaStore.Images.Media.TITLE, fileName);

            values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");

            // imageUri is the current activity attribute, define and save it for later usage

            imageUri = getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

            /**** EXTERNAL_CONTENT_URI : style URI for the "primary" external storage volume. ****/


            // Standard Intent action that can be sent to have the camera
            // application capture an image and return it.

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

            startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

            /*************************** Camera Intent End ************************/


        }
onActivityResult方法如下所示:

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

        if (resultCode == RESULT_OK) {

            /*********** Load Captured Image And Data Start ****************/

            String imageId = convertImageUriToFile(imageUri, CameraActivity);


            //  Create and excecute AsyncTask to load capture image

            new LoadImagesFromSDCard().execute("" + imageId);

            /*********** Load Captured Image And Data End ****************/


        } else if (resultCode == RESULT_CANCELED) {

            Toast.makeText(this, " Picture was not taken ", Toast.LENGTH_SHORT).show();
        } else {

            Toast.makeText(this, " Picture was not taken ", Toast.LENGTH_SHORT).show();
        }
    }
}
//不要使用data.getData(),因为它在某些设备中返回null

因此,使用光标获取捕获的图像

@Override
protected void onActivityResult(int requestCode, int resultCode,
    Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);

    if (resultData != null) {

    String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    projection, null, null, null);
            int column_index_data = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToLast();

            String imagePath = cursor.getString(column_index_data);
            Bitmap bitmapImage = BitmapFactory.decodeFile(imagePath );
            imageView.setImageBitmap(bitmapImage );

        }

您是否包含了
写入外部存储
权限?您是否在清单中添加了权限?是的,我已添加了所有权限我使用您的代码并获得了一个异常,java.lang.SecurityException:权限拒绝:写入com.android.providers.media.MediaProvider uricontent://media/external/images/media 从pid=6550,uid=10103需要android.permission.WRITE_EXTERNAL_存储,或grantUriPermission()。您没有在清单文件中添加权限@用户_1191我添加了onActivityResult方法。我添加了权限我添加了有问题的权限。现在我缺少convertImageUriToFile()
@Override
protected void onActivityResult(int requestCode, int resultCode,
    Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);

    if (resultData != null) {

    String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    projection, null, null, null);
            int column_index_data = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToLast();

            String imagePath = cursor.getString(column_index_data);
            Bitmap bitmapImage = BitmapFactory.decodeFile(imagePath );
            imageView.setImageBitmap(bitmapImage );

        }