How to cut two images in the same Activity?

Asked

Viewed 48 times

1

I’m using this repository to cut images. But I’m not able to cut two images in the same activity, and one is oval and the other is rectangular. Every time I click on both, the cut is the same.

Below is the code of the oval cut:

private CircleImageView mCircleImageView;
private static final int GALLERY_REQUEST = 1;
private Uri mImageUri;

mCircleImageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        Intent galleryIntent = new Intent();
        galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        galleryIntent.setType("image/*");
        startActivityForResult(galleryIntent, GALLERY_REQUEST);
    }
});
}

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

    if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK) {

        Uri imageUri = data.getData();
        CropImage.activity(imageUri)
            .setGuidelines(CropImageView.Guidelines.ON)
            .setAspectRatio(1, 1)
            .setCropShape(CropImageView.CropShape.OVAL)
            .setBackgroundColor(R.color.pretotransparente)
            .setBorderLineColor(R.color.vermelhotransparente)
            .setCropShape(CropImageView.CropShape.OVAL)
            .start(this);

    }

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);

        if (resultCode == RESULT_OK) {
            mImageUri = result.getUri();



            mCircleImageView.setImageURI(mImageUri);
        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
            Exception error = result.getError();
        }
    }
}

Solved The problem was with onActivityResult

https://stackoverflow.com/questions/5030565/multiple-onactivityresult-for-1-activity

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

    if(requestCode == GALLERY_REQUEST && resultCode == RESULT_OK){

        Uri imageUri = data.getData();
        CropImage.activity(imageUri)
                .setGuidelines(CropImageView.Guidelines.ON)
                .setAspectRatio(1, 1)
                .setCropShape(CropImageView.CropShape.OVAL)
                .setBackgroundColor(R.color.pretotransparente)
                .setBorderLineColor(R.color.vermelhotransparente)
                .setCropShape(CropImageView.CropShape.OVAL)
                .start(this);

    }

    if(requestCode == GALLERY_REQUEST2 && resultCode == RESULT_OK){
        Uri imageUri = data.getData();
        CropImage.activity(imageUri)
                .setGuidelines(CropImageView.Guidelines.ON)
                .setBackgroundColor(R.color.pretotransparente)
                .setBorderLineColor(R.color.vermelhotransparente)
                .setMaxCropResultSize(1000,400)
                .setMinCropResultSize(1000,400)
                .start(this);

    }

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);

        if (resultCode == RESULT_OK) {
            mImageUri = result.getUri();
            mCircleImageView.setImageURI(mImageUri);
            mCapaSelect.setImageURI(mImageUri);


        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
            Exception error = result.getError();
        }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.