2017-07-24 58 views
-1

这里是我的相机意图。从相机捕捉图像和裁剪不起作用

  File file = getExternalFilesDir(Environment.DIRECTORY_DCIM); 
      file.mkdirs(); 
      File output = new File(file, "profile_image"); 
      if (output.exists()) { 
       output.delete(); 
      } 
      Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

      captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, output); 
      startActivityForResult(captureIntent, PublicValues.IMAGE_FROM_CAMERA); 

在onActivityresult

if (requestCode == PublicValues.IMAGE_FROM_CAMERA) { 

       if (mPhotoUri != null) { 
        performCrop(mPhotoUri); 
       } else { 
        pictureUri = data.getData(); 
        performCrop(pictureUri); 
       } 

和作物意图

  Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
      cropIntent.setDataAndType(picUri, "image/*"); 
      cropIntent.putExtra("crop", "true"); // set crop properties 
      cropIntent.putExtra("aspectX", 1); // indicate aspect of desired crop(ratio) 
      cropIntent.putExtra("aspectY", 1); 
      cropIntent.putExtra("return-data", true); // retrieve data on return 
      cropIntent.putExtra("outputX", profileImage.getWidth()); // indicate output X and Y 
      cropIntent.putExtra("outputY", profileImage.getHeight()); 

      startActivityForResult(cropIntent, PublicValues.IMAGE_CROP); 

它正常工作与API 19的设备,但在崩溃棉花糖设备。

崩溃报告是这样的: -

Caused by android.os.FileUriExposedException: file:///storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20170721-WA0014.jpg exposed beyond app through Intent.getData() 
android.os.StrictMode.onFileUriExposed (StrictMode.java:1813) 
android.net.Uri.checkFileUriExposed (Uri.java:2360) 
android.content.Intent.prepareToLeaveProcess (Intent.java:8981) 
android.content.Intent.prepareToLeaveProcess (Intent.java:8942) 
android.app.Instrumentation.execStartActivity (Instrumentation.java:1583) 
android.app.Activity.startActivityForResult (Activity.java:4228) 
android.support.v4.app.BaseFragmentActivityJB.startActivityForResult (BaseFragmentActivityJB.java:50) 
android.support.v4.app.FragmentActivity.startActivityForResult (FragmentActivity.java:79) 
+2

你能后的错误日志? –

+0

@AjilO。看到我的编辑 – ben10

+0

所有的权限都给你的应用程序,对吗? –

回答

2

使用摇篮:

compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+' 

,并尝试这个办法:

private void performCrop(Uri imageUri) { 
    CropImage.activity(imageUri) 
      .setGuidelines(CropImageView.Guidelines.ON) 
      .setCropShape(CropImageView.CropShape.RECTANGLE) 
      .setAspectRatio(1, 1) 
      .setMultiTouchEnabled(true) 
      .start(this); 
} 
+0

它的作品,我可以得到裁剪图像? – ben10

+1

在你的项目中实现这个gradle文件,并在你的类中写入这个方法,然后调用这个performCrop()方法的参数imageUri,你想要裁剪。 –

相关问题