我正在尝试用Swift做一个简单的裁剪功能。我正在尝试使用CGImageCreateWithImageInRect函数-它工作得很好,但质量很差。我是不是漏掉了什么?
func retriveCroppedImage(){
let yratio: CGFloat = imgviewrect.size.height / chosenImage.size.height
let xratio: CGFloat = imgviewrect.size.width / chosenImage.size.width
var cliprect = CGRectMake(centerpoint.x - vWidth/2, centerpoint.y - vHeight/2, vWidth, vHeight)
print("cliprect top \(cliprect.size)")
cliprect.size.height = cliprect.size.height / xratio;
cliprect.size.width = cliprect.size.width / xratio;
cliprect.origin.x = cliprect.origin.x / xratio + imgviewrect.origin.x / xratio
cliprect.origin.y = cliprect.origin.y / yratio - imgviewrect.origin.y / xratio
print("cliprect On Image \(cliprect)")
let imageRef = CGImageCreateWithImageInRect(chosenImage.CGImage, cliprect )
croppedImg = UIImage(CGImage: imageRef!, scale: UIScreen.mainScreen().scale, orientation: chosenImage.imageOrientation)
print("Operation complete");
}
屏幕截图:Main VC
裁剪后,我得到了Cropped Image
发布于 2016-01-04 03:18:32
在尝试了所有选项后,我意外地发现我在故事板上的Image View中设置了Alpha。CGImageCreateWithImageInRect函数没有任何错误。现在,我的裁剪应用程序可以正常工作了。但是感谢你们所有人的建议。
https://stackoverflow.com/questions/34570318
复制相似问题