Camera Crop-Code在Android 7.0

时间:2017-06-24 01:02:42

标签: android camera crop android-7.0-nougat

我的代码适用于Android 4至Android 6.x的所有设备 但在我在Android 7.0上更新我的设备后,相机代码无法正常工作。我被黑屏了!

我可以从相机拍摄,但之后如果我想裁剪图像我会回到屏幕

可能是作物funktion没有得到位图的核心路径 screen

任何想法?这是代码:

     img = (ImageView) findViewById(R.id.imageView);
        img_original = (ImageView) findViewById(R.id.imageView_original);
    }

    public void Capture(View view) {
        Capture_Cam();
    }

    private void Capture_Cam() {
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, 1);

    }

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


        if (requestCode == 1 && resultCode == RESULT_OK && data != null) {

                picUri = data.getData();
                try {
                    // bitmap2 = MediaStore.Images.Media.getBitmap(this.getContentResolver(), picUri); // bitmap2 = original before cur
                    bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse("file://"+picUri));
                    img_original.setImageBitmap(bitmap);

                } catch (IOException e) {
                    e.printStackTrace();
                }
                performCrop();

        } else if (requestCode == 2) {

            bitmap2=(Bitmap) data.getExtras().get("data");
            img.setImageBitmap(bitmap2);

         }else{
            super.onActivityResult(requestCode, resultCode, data);
        }

    }

       private void performCrop(){
        try {

            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            //indicate image type and Uri
            cropIntent.setDataAndType(picUri, "image/*");
            cropIntent.putExtra("crop", "true");
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            cropIntent.putExtra("outputX", 100);
            cropIntent.putExtra("outputY", 100);
            cropIntent.putExtra("scale", true);
            cropIntent.putExtra("return-data", true);
            startActivityForResult(cropIntent, 2);
            Toast toast = Toast.makeText(this, "Done", Toast.LENGTH_SHORT);
        }
        catch(ActivityNotFoundException anfe){
            //display an error message
            String errorMessage = "Whoops - your device doesn't support the crop action!";
            Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
            toast.show();
        }

    }

}

0 个答案:

没有答案