OnActivityResult从CropIntent

时间:2015-08-23 09:28:52

标签: android image

当我尝试使用相机并获取该图像并尝试使用cropintent进行裁剪时 但是从CropIntent返回OnActivityResult后,意图值显示为空

在Dialog上,我使用相机,对话框代码在这里

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    File file=null;
                    try {

                        file = createImageFile();
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        Log.e("File creation","Error occured during file creation");
                        e1.printStackTrace();
                    }

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


                dialog.dismiss();

OnActivityReultCode是

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

    String path="";
    switch (requestCode) {


    case PICK_FROM_CAMERA:
        if(resultCode==RESULT_OK && !currentPhotopath.isEmpty()){


             mImageCaptureUri = intent.getData();
            Log.e("Camera path","" +path);
            Log.e("Camera uri",mImageCaptureUri.toString());*/

               performCrop();


        }
        else{
            Toast.makeText(getApplicationContext(),"Error occured",Toast.LENGTH_SHORT).show();
        }

        break;


    case PIC_CROP:

           Bundle extras = intent.getExtras();
           Bitmap bp = extras.getParcelable("data");
           photoView.setImageBitmap(bitmap);


        break;

    default:
        Toast.makeText(getApplicationContext(),"Could not load image", Toast.LENGTH_SHORT).show();
        break;
    }


    super.onActivityResult(requestCode, resultCode, intent);
}

并且performCrop方法

private void performCrop()
{
    Intent cropIntent = new Intent("com.android.camera.action.CROP");
    cropIntent.setDataAndType(mImageCaptureUri, "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 );

}

0 个答案:

没有答案