我正在使用 Swift 编写圆形裁剪函数。几乎所有功能都已经实现,但是当我保存裁剪后的照片时,它会略微模糊:
不确定这里是否可见,但在我的iPhone上我可以看到一个微小的模糊区别。我没有放大图像的实际大小。我正在使用最大缩放因子为1.0的UIScrollView。裁剪代码如下:
func didTapOk() {
let scale = scrollView.zoomScale
let newSize = CGSize(width: image!.size.width*scale, height: image!.size.height*scale)
let offset = scrollView.contentOffset
UIGraphicsBeginImageContext(CGSize(width: 240, height: 240))
let circlePath = UIBezierPath(ovalInRect: CGRect(x: 0, y: 0, width: 240, height: 240))
circlePath.addClip()
var sharpRect = CGRect(x: -offset.x, y: -offset.y, width: newSize.width, height: newSize.height)
sharpRect = CGRectIntegral(sharpRect)
image?.drawInRect(sharpRect)
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
UIImageWriteToSavedPhotosAlbum(finalImage, nil, nil, nil)
}
我正在尝试使用CGRectIntegral
来改善结果,但似乎没有任何区别。您有什么建议可以帮助我改善这个问题吗?
true
传递到函数的opaque
参数中。如果你想要透明度,应该传递false
。 - Hamish