我想从相机中裁剪图像,所以相机中有一个矩形边框,结果将是裁剪后的图像 喜欢这张图片
答案 0 :(得分:0)
expectedResult = [i for i in my_list if i['source'] == 'family']
答案 1 :(得分:0)
答案 2 :(得分:0)
将Apple's developer documentation与Pranavan Sp弃用的答案结合起来,跳过钟声,您将得到:
extension UIImage {
func cropToRect(rect: CGRect!) -> UIImage? {
let scaledRect = CGRect(x: rect.origin.x * self.scale, y: rect.origin.y * self.scale, width: rect.size.width * self.scale, height: rect.size.height * self.scale);
guard let imageRef: CGImage = self.cgImage?.cropping(to:scaledRect)
else {
return nil
}
let croppedImage: UIImage = UIImage(cgImage: imageRef, scale: self.scale, orientation: self.imageOrientation)
return croppedImage
}
}