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

如何实现,在拍照的时候,只生成高亮区域对应的图片? #735

Open
AbnerPei opened this issue Oct 17, 2024 · 1 comment

Comments

@AbnerPei
Copy link

image

如上图,自定义camera,我的实现思路:
在normalPreView上新增上、中、下三个view,点击拍照按钮,获取图片后再调用UIImage的cropImage(toRect)裁剪:但是结果不理想

BH130 - 拍照图片 img width is 485.0, height is 1050.0
BH130 - 拍照图片 resizeImg width is 485.0, height is 486.0
BH130 - 拍照图片 kwidth is 414.0

我是414 * 896的手机(xs max)

代码如下:

    func cameraController(_ cameraController: CameraController, didFinishWithResult result: CameraController.Result, location: CLLocation?) {
        if case .image(let img) = result {
            BHLog("BH130 - 拍照图片 img width is \(img.size.width), height is \(img.size.height)")

            let resizeImg = img.cropImage(toRect: CGRect(x: 0, y: BHApp.statusBarHeight + 66~ + 87~, width: kWidth, height: kWidth), viewWidth: kWidth, viewHeight: kHeight)
            if let resizeImg {
                BHLog("BH130 - 拍照图片 resizeImg width is \(resizeImg.size.width), height is \(resizeImg.size.height)")
                BHLog("BH130 - 拍照图片 kwidth is \(kWidth)")
//                self.uploadFoodImage(img: resizeImg)
            } else {
                BHLog("BH130 - 拍照图片 resizeImg 失败")
            }
            cameraController.dismiss(animated: true) {
                #warning("version - 1.3.0")
//                self.uploadImage(editedImage: img)
            }
        }
    }
@AbnerPei
Copy link
Author

cropImage(toRect 返回的比例,不是1:1,请问有什么方法处理吗?上网搜了一圈,都有问题!

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