CanHub / Android-Image-Cropper

Image Cropping Library for Android, optimised for Camera / Gallery.
Apache License 2.0
1.26k stars 261 forks source link

will you please provide crop library properly in java(Android)... #407

Closed Aneel9kumar closed 2 years ago

Aneel9kumar commented 2 years ago

I can give you an example of how I implemented it. It works really very well. Hope that helps.

first update to actual library implementation 'com.github.CanHub:Android-Image-Cropper:4.2.1'

second define CropImageContractOptions :

 public CropImageContractOptions getCropOptions(Uri imageUri) { 
        return new CropImageContractOptions(imageUri,new CropImageOptions())
                .setActivityTitle("Cropper")
                .setGuidelines(CropImageView.Guidelines.ON)
                .setCropShape(CropImageView.CropShape.RECTANGLE)
                .setActivityMenuIconColor(ContextCompat.getColor(mContext, R.color.appColor))
                .setAllowRotation(true)
                .setAllowFlipping(true)
                .setOutputCompressFormat(Bitmap.CompressFormat.PNG)
                .setAllowCounterRotation(true)
                .setImageSource(true,false)
                .setScaleType(CropImageView.ScaleType.CENTER);
    }

third define ActivityResultLauncher:

public ActivityResultLauncher<CropImageContractOptions> cropImageActivityResultLauncher = registerForActivityResult(
new CropImageContract(),
new ActivityResultCallback<CropImageView.CropResult>() {
                @Override
                public void onActivityResult(CropImageView.CropResult result) {
                    if (result.isSuccessful()) {
                        Uri resultUri = result.getUriContent();
            Bitmap bmp = result.getBitmap();                       
                    } else {
                        Log.e(TAG, "onActivityResult...Error CropImage: "+result.getError());
                    }
                }
            }
}

Fourth call like

CropImageContractOptions options = getCropOptions(uri);
cropImageActivityResultLauncher.launch(options);

Alejandro `

Originally posted by @AlejandroGomz in https://github.com/CanHub/Android-Image-Cropper/discussions/236#discussioncomment-2610240

Canato commented 2 years ago

Hey welcome 👋 to the library and thanks for the Issue.

Can you please follow the template we have for issues? 🙏 There are many points on the template that will help me to help you.

I will close 🔴 this issue so you can reopen following the template

Is important to remember that my work here is a volunteer and to save time and have better answer help me that people use the templates.

Thanks!! 🎉