crop image implementation in java not working

100 Views Asked by At

I want to use a crop image library to pick and crop an image from the gallery but even when I have added the library, the activity wasn't recognized in the android studio. from the github link that has the crop image library, they are only showing the example using kotlin but I want to use java for it. I'm also using a Fragment in doing it This is the library that I used implementation"com.vanniktech:android-image-cropper:4.5.0" and I have added the crop image activity in my manifest file like this

     I got this error: cannot find symbol
            CropImage.activity(imageUri)
    
    private void pickProfileImage(){
            CropImage.activity(imageUri)
                    .setAspectRatio(1, 1)
                    .start(getContext());
    
        }
    
        @Override
        public 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.activity(data);
                if (resultCode == RESULT_OK) {
                    imageUri = result.getResult(data);
                    profileImage.setImageURI(imageUri);
                } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                    Exception error = result.getError();
                    Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(), "Error Occurred Try Again", Toast.LENGTH_SHORT).show();
                }
            }
        }
1

There are 1 best solutions below

2
On

Load the image file using Java ImageIO (which is built into Java) BufferedImage image = ImageIO.read(new File("C:\path\to\kitten.jpg")); Get a cropped version (x, y, width, height) (0,0 is top left corner) ... Save the image back to a File.