Search code examples
androidcoordinatescrop

Cropped area rectangle show where previously cropped area like whats app


I'm developing Photoshop type app in which crop tools is using to crop image and i'm using default crop intent, when i cropped image i get bundle in which i got Rect(0,0-2,122) left,top,right,bottom but my point is when i cropped first time and again i cropped the cropper show its previously cropped area not default area and in crop intent.

CropIntent.putExtra("outputX", imageWidth);
CropIntent.putExtra("outputY", imageHeight);
CropIntent.putExtra("aspectX", 100);
CropIntent.putExtra("aspectY", -100);
CropIntent.putExtra("spotlightX", 10);
CropIntent.putExtra("spotlightY", -10);

I pass l,t,r,b like this, i know this is wrong but i tried aspect x and aspect y are ratios but spot light is what, i don't know. can i place cropper at previously cropped area on same image.


Solution

  • You can use this library from here

    and use below method two recover the ratio on the image and call it where your image is to be cropped and remember when Activity is switched do not finish it.

     public void updateCurrentCropViewOptions() {
        CropImageViewOptions options = new CropImageViewOptions();
        options.scaleType = mCropImageView.getScaleType();
        options.cropShape = mCropImageView.getCropShape();
        options.guidelines = mCropImageView.getGuidelines();
        options.aspectRatio = mCropImageView.getAspectRatio();
        options.fixAspectRatio = mCropImageView.isFixAspectRatio();
        options.showCropOverlay = mCropImageView.isShowCropOverlay();
        options.showProgressBar = mCropImageView.isShowProgressBar();
        options.autoZoomEnabled = mCropImageView.isAutoZoomEnabled();
        options.maxZoomLevel = mCropImageView.getMaxZoom();
        options.flipHorizontally = mCropImageView.isFlippedHorizontally();
        options.flipVertically = mCropImageView.isFlippedVertically();
    }