如何快速裁剪图​​像

时间:2018-08-14 09:09:31

标签: swift image-processing

我想从相机中裁剪图像,所以相机中有一个矩形边框,结果将是裁剪后的图像 喜欢这张图片

The Image

3 个答案:

答案 0 :(得分:0)

expectedResult = [i for i in my_list if i['source'] == 'family']

答案 1 :(得分:0)

enter image description here

嗨,您可以使用此代码调整图片的大小。

答案 2 :(得分:0)

Apple's developer documentationPranavan 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
    }
}