Yalantis / uCrop

Image Cropping Library for Android
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/
11.89k stars 2.16k forks source link

Add feature to continue cropping based on the last edit #412

Open azri92 opened 6 years ago

azri92 commented 6 years ago

As of v 2.2.2, uCrop does not:

  1. return information of last state when cropping
  2. accept info of saved state and lay out views based on the the provided state.

The goal is to enable users to continue editing the same image that was already edited based on the last saved state.

Ideas for this

Saved state to be returned post-crop should include:

  1. Image matrix.
  2. Crop rect.

To continue editing:

  1. Have a withSavedStateOption(matrix, cropRect) in uCrop intent builder.
  2. In CropImageView.onImageLaidOut(), set up using saved state info provided if available.
azri92 commented 6 years ago

I do notice that cropOffsetX & cropOffsetY are provided in crop result but I'm not sure how to use these (and if they're sufficient to rebuild state).

maxtracking commented 6 years ago

@Legementarion It looks like with a bit of hacking it's possible to restore the cropping state. What I've done so far:

The only problem with above is that I cannot easily reset overlay's rectangle. Any ideas?

azri92 commented 6 years ago

@maxtracking Maybe you can check out this PR (on a forked version): https://github.com/photobook-worldwide-mobile/uCrop/pull/1

@Legementarion let me know if you would like me to create a direct PR to this repo.

Legementarion commented 6 years ago

@azri92 Hi! Yep, I would like :) Create pull request please, for both branches, 'develop' and 'non_native' :)

maxtracking commented 6 years ago

@azri92 Thanks, I will have a look.

jackyhieu1211 commented 4 years ago

@azri92 https://github.com/photobook-worldwide-mobile/uCrop I run your demo and get error below java.lang.NullPointerException: Attempt to read from field 'float com.yalantis.ucrop.model.BleedPercentage.left' on a null object reference at com.yalantis.ucrop.view.OverlayView.drawBleedRects(OverlayView.java:569) at com.yalantis.ucrop.view.OverlayView.onDraw(OverlayView.java:390) at android.view.View.draw(View.java:21473)

Can you fix it. thanks