Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Set initial cropRect binding #6

Open
f0enix opened this issue Nov 27, 2022 · 0 comments
Open

Suggestion: Set initial cropRect binding #6

f0enix opened this issue Nov 27, 2022 · 0 comments

Comments

@f0enix
Copy link
Contributor

f0enix commented Nov 27, 2022

is it possible to provide an initial crop rect to the cropper? For example, add a binding cropRect to the cropper view and then anyone using it can provide an initial cropRect. The cropper view will then adjust the crop area. Then on pressing the crop button, instead of only keeping the the calculated cropRect internally to the cropper view, also apply it in the binding to expose it for the caller. Something like:

struct CropperView: View {
    var inputImage: UIImage
    @Binding var cropRect = CGRect.Zero
}
/*adjust initial crop view here*/

//button action
Button (action : {
        //由于CGRect是先到坐标再开始生成的,所以要这样减去剪裁栏的部分
         cropRect = CGRect(x: imageDisplayWidth/2 + currentPositionCrop.width - cropWidth/2,
                                          y: imageDisplayHeight/2 + currentPositionCrop.height - cropHeight/2,
                                          width: cropWidth,
                                          height: cropHeight)
          croppedImage = cropImage(UIImage(named: "image")!, toRect: rect, viewWidth: imageDisplayWidth, viewHeight: imageDisplayHeight)!
          self.presentationMode.wrappedValue.dismiss()
}) {
    Image(systemName: "crop")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant