我编写了以下函数:
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"但是我不知道为什么种植过程会失败。
发布于 2020-08-07 10:01:37
图像宽3024,而剪裁矩形的x坐标为3024.5。在图像之外。
https://stackoverflow.com/questions/63299249
复制相似问题