我想实现一个可以使用红色CGRect
的帧裁剪图像的视图控制器。我尝试了以下代码,但似乎我的裁剪逻辑已经过时了。裁剪后的图像似乎只是原始图像的一小部分......我怎样才能抓住红色矩形CGRect
内的任何内容的UII图像?
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
picker.dismiss(animated: true, completion: nil)
if let x = info[UIImagePickerControllerOriginalImage] as? UIImage {
let a = x.cgImage?.cropping(to: CGRect(x: 100, y: 100, width: 200, height: 50))
let b = UIImage(cgImage: a!)
let y = UIImageView(frame: self.view.frame)
y.image = b
self.view.addSubview(y)
}
}