1 2 3 4 5 6 7 8 9 10 11 12 13 14
| extension UIImage { func imageAtRect(rect: CGRect) -> UIImage{ var rect = rect rect.origin.x *= self.scale rect.origin.y *= self.scale rect.size.width *= self.scale rect.size.height *= self.scale let imageRef = self.cgImage!.cropping(to: rect) let image = UIImage(cgImage: imageRef!, scale: self.scale, orientation: self.imageOrientation) return image } }
|