gpt4 book ai didi

ios - 以编程方式从底部裁剪图像

转载 作者:搜寻专家 更新时间:2023-10-30 22:01:22 25 4
gpt4 key购买 nike

我正在开发自定义相机应用程序。事情进展顺利。

但是我在从底部裁剪图像时遇到了问题。即裁剪后的图像与原始图像具有完全相同的宽度,但高度将为原始图像的 1/3,并且必须从底部开始。

For Example Like this is the full image I need the red part only

最佳答案

Swift 3 解决方案:

func cropBottomImage(image: UIImage) -> UIImage {
let height = CGFloat(image.size.height / 3)
let rect = CGRect(x: 0, y: image.size.height - height, width: image.size.width, height: height)
return cropImage(image: image, toRect: rect)
}

用矩形裁剪的辅助方法:

func cropImage(image:UIImage, toRect rect:CGRect) -> UIImage{
let imageRef:CGImage = image.cgImage!.cropping(to: rect)!
let croppedImage:UIImage = UIImage(cgImage:imageRef)
return croppedImage
}

关于ios - 以编程方式从底部裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39971527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com