我想使点击图像区域缩放。
当我对图像应用gpuimagebulgetharformonfilter时,它在中心点(0.5,0.5)处正常工作,但当中心点更改时,对图像的影响不会作为给定的中心点应用。
图像方块正常工作。
图像宽度>图像高度。中心点(0.5,0.2)适用于(0.5,0.1),中心点(0.5,0.8)适用于(0.5,0.9)
图像宽度
func tapGesture(_ sender: Any){
let points = tap.location(ofTouch: 0, in: ivPic)
let stillImageFilter = GPUImageBulgeDistortionFilter()
stillImageFilter.center = CGPoint(x: points.x / ivPic.frame.size.width, y: points.y / ivPic.frame.size.height)
stillImageFilter.radius = 0.1
stillImageFilter.scale = 0.1
ivPic.image = stillImageFilter.image(byFilteringImage: ivPic.image)
}
最佳答案
试试这个
func tapGesture(_ sender: Any) {
let points = tap.location(in: ivPic)
let stillImageFilter = GPUImageBulgeDistortionFilter()
let aspectRatio = ivPic.frame.size.height / ivPic.frame.size.width
stillImageFilter.center = CGPoint(x: points.x / ivPic.frame.size.width, y: ((((points.y / ivPic.frame.size.height) * aspectRatio) + 0.5) - (0.5 * aspectRatio)))
stillImageFilter.radius = 0.1
stillImageFilter.scale = 0.1
ivPic.image = stillImageFilter.image(byFilteringImage: ivPic.image)
}