【问题标题】:Cant crop image from camera无法从相机裁剪图像
【发布时间】:2016-03-28 11:43:18
【问题描述】:

首先 - 我很抱歉我的英语不好。 我尝试从相机照片中进行裁剪。

这是我的 openCamera 方法:

private void openCamera() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
    // ******** code for crop image
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", 0);
    intent.putExtra("aspectY", 0);
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 150);

    try {

        intent.putExtra("return-data", true);
        startActivityForResult(intent, PICK_FROM_CAMERA);

    } catch (ActivityNotFoundException e) {
    // Do nothing for now
    }
}

这里是 ActivityForResult:

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

        if (requestCode == PICK_FROM_CAMERA) {
            Bundle extras = data.getExtras();
            if (extras != null) {
                photo = extras.getParcelable("data");
            }
        }
    }

但它与...崩溃了

03-28 14:40:41.791 15198-15198/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               java.lang.IllegalStateException: Could not execute method of the activity
                                                   at android.view.View$1.onClick(View.java:3050)
                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=file:///data/data/com.android.camera/files/crop-temp (has extras) }
                                                   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1518)
                                                   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1390)
                                                   at 

完全不知道...

【问题讨论】:

标签: android camera crop


【解决方案1】:

使用以下代码

Intent cropIntent = new Intent("com.android.camera.action.CROP");     
cropIntent.setDataAndType(picUri, "image/*");    
cropIntent.putExtra("crop", "true");    
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);    
cropIntent.putExtra("outputX", 256);    
cropIntent.putExtra("outputY", 256);    
cropIntent.putExtra("return-data", true);    
startActivityForResult(cropIntent, PIC_CROP);

OnActivityResult() 方法 Bundle extras = data.getExtras(); //get the cropped bitmap Bitmap thePic = extras.getParcelable("data");

【讨论】:

  • 出了什么问题..?
  • 我不确定,但你的答案很接近正确,Abhishek。看起来我们必须通过意图 MediaStore.ACTION_IMAGE_CAPTURE 获取照片,并且只有在它使用意图 com.android.camera.action.CROP 和照片的 url 之后。再次感谢您的回答)
  • 我试试这个,但它不适合我。我已经通过github.com/lorensiuswlt/AndroidImageCrop 解决了它:)非常简单而且很好)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 2014-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多