Android取消裁剪不会返回活动结果

Android取消裁剪不会返回活动结果,android,bitmap,crop,Android,Bitmap,Crop,我可以从gallery中选择一幅图像,进行裁剪,并将其作为包获取。我以这种方式检索它: if (resultCode == Activity.RESULT_OK) { if (requestCode == SELECT_IMAGE || requestCode == SELECT_LANDSCAPE_IMAGE) { Bundle extras = data.getExtras(); Bitmap photo = extras.getPar

我可以从gallery中选择一幅图像,进行裁剪,并将其作为
获取。我以这种方式检索它:

if (resultCode == Activity.RESULT_OK) {
      if (requestCode == SELECT_IMAGE || requestCode == SELECT_LANDSCAPE_IMAGE) {
           Bundle extras = data.getExtras();
           Bitmap photo = extras.getParcelable("data");
                .........................
      }
}

一切正常。但当我取消裁剪时,不会收到任何包。我想在取消裁剪时接收实际位图。我该怎么做呢?

我找到了解决方案:

if (requestCode == CROP_FROM_CAMERA && resultcode == RESULT_CANCELED {
  // crop was cancelled
}

如果他们取消了,它可能不会返回结果“OK”。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == AppConstant.PICK_PROFILE_PIC) {
        // getActivity();
        if (resultCode == Activity.RESULT_OK && data != null) {
            selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(
                    selectedImage, filePathColumn, null, null, null);

            // some devices (OS versions return an URI of com.android
            // instead of com.google.android
            if (selectedImage.toString().startsWith(
                    "content://com.android.gallery3d.provider")) {
                // use the com.google provider, not the com.android
                // provider.
                selectedImage = Uri.parse(selectedImage.toString().replace(
                        "com.android.gallery3d",
                        "com.google.android.gallery3d"));
            }

            if (cursor != null) {
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                if (selectedImage.toString().startsWith(
                        "content://com.google.android.gallery3d")) {
                    columnIndex = cursor
                            .getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
                    if (columnIndex != -1) {
                        new GetBitmap(getApplicationContext(), selectedImage)
                                .execute();
                    }
                } else if (selectedImage.toString().startsWith(
                        "content://com.google.android.apps.photos.content")) {
                    new GetBitmap(getApplicationContext(), selectedImage).execute();
                } else {
                    cursor.moveToFirst();
                    mPicturePath = cursor.getString(columnIndex);
                    ImageUtils.rotateImage(getApplicationContext(), mPicturePath);
                    addGalleryImage(mPicturePath);
                }
            }
            cursor.close();
        }
        performCrop();

    } else if (requestCode == AppConstant.CLICK_IMAGE) {
        File f = new File(Environment.getExternalStorageDirectory()
                .toString());
        for (File temp : f.listFiles()) {
            if (temp.getName().equals(AppConstant.TEMP_IMAGE_NAME)) {
                f = temp;
                break;
            }
        }
        mPicturePath = f.toString();

        mBitmap = ImageUtils.rotateImage(this, mPicturePath);
        ImageUtils.setBitmapToView(mBitmap, mProfilePic);

       Toast.makeText(RegistrationActivity.this, mPicturePath + "", Toast.LENGTH_LONG).show();

    } else if (requestCode == AppConstant.CROP_IMAGE && resultCode != RESULT_CANCELED) {
        // get the returned data
        Bundle extras = data.getExtras();
        // get the cropped bitmap

        Bitmap thePic = extras.getParcelable("data");
            // retrieve a reference to the ImageView

            // display the returned cropped image
            GraphicsUtil graphicUtil = new GraphicsUtil();
            // picView.setImageBitmap(graphicUtil.getRoundedShape(thePic,(float)1.5,92));
            mProfilePic.setImageBitmap(graphicUtil.getCircleBitmap(
                    thePic, 16));
        Toast.makeText(RegistrationActivity.this, mPicturePath + "", Toast.LENGTH_LONG).show();

    }
    else if (requestCode == AppConstant.CROP_IMAGE && resultCode == RESULT_CANCELED) {
        Toast.makeText(RegistrationActivity.this, mPicturePath + "", Toast.LENGTH_LONG).show();

    }
}