裁剪 UIImage 失败

Cropping UIImage fails

我正在尝试将图像从 UIImagePicker 裁剪到特定的矩形,但我收到的是深色而不是图像(这似乎是图像的颜色主题)。

首先是我的 imagePicker 函数:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
         let originalImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
        imagePicker.dismiss(animated: true, completion: nil)
        if originalImage == nil { print("Error Not Found An Image")}
            imageView.image = originalImage
            let croppedImage = cropImage(image: originalImage, rect: CGRect(x: 0.13, y: 0.12, width: 0.74, height: 0.75))
            imageView.image = croppedImage
}

还有我的裁剪功能

    func cropImage (image: UIImage, rect: CGRect) -> UIImage {

        let resImage = CIImage(image: image, options: [:])
        let croppedImage = resImage?.cropped(to: rect)
        let img = UIImage(ciImage: croppedImage!, scale: 1, orientation: image.imageOrientation)

        return img
    }

问题出在矩形的值上。就我而言,它们太小了。

感谢 badhanganesh 的提示