Я написал следующую функцию:
fileprivate func crop(image: UIImage, rect: CGRect) -> CGImage? {
debugPrint("imageHeight: \(image.cgImage?.height)")
debugPrint("imageWidth: \(image.cgImage?.width)")
debugPrint("cropZone: \(rect)")
guard let cropped = image.cgImage?.cropping(to: rect) else {
debugPrint("cropping process failed")
return nil
}
debugPrint("cropped")
return cropped
}
, которая дает мне результат:
"imageHeight: Optional(4032)"
"imageWidth: Optional(3024)"
"cropZone: (3024.5166500171667, 1605.1421763895605, 949.3006961766132, 251.7156472208785)"
[Unknown process name] CGImageCreateWithImageProvider: invalid image size: 0 x 0.
"cropping process failed"
Но я понятия не имею, почему процесс обрезки терпит неудачу.