How to croping image with source just from camera with Canhub Android Image Cropper with Java

2.6k views Asked by At

I want to croping image from other activity to another activity with Canhub Android Image Cropper library. This is my code :

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {
            mCropImageUri = result.getOriginalUri();

            createImage();
        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
            AppLogger.e(result.getError().getMessage());
        }
    }

    if (requestCode == PermissionCheckUtils.LOCATION_PERMISSION_REQUEST_CODE && resultCode == RESULT_OK) {
        getLocation();
    }
}

and this when i access the camera :

private void openCropImage() {
    Intent intent = CropImage.activity().setGuidelines(CropImageView.Guidelines.ON).getIntent(this);
    startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}

with these code, i open camera but source include galery. My question is how to open the croper with source just from camera. I already read the documentation but I'm confused : https://github.com/CanHub/Android-Image-Cropper

1

There are 1 answers

1
Kishan Mevada On

It is very simple !!

In Your openCropImage() Function set following code :

Intent intent = CropImage
                    .activity()
                    .setImageSource(includeGallery = false, includeCamera = true)
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .getIntent(this);

startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);

That's it !! Happy Coding :-)