我想点击图像区域缩放。
当我将GPUImageBulgeDistortionFilter应用于图像时,它可以在中心点(0.5,0.5)正常工作,但是当中心点改变时,对图像的效果不适用于给定的中心点。
形象广场正常运作。
图片宽度>图像高度。中心点(0.5,0.2)适用于(0.5,0.1),中心点(0.5,0.8)适用于(0.5,0.9)
图像宽度<图像高度。中心点(0.5,0.2)适用于(0.5,0.3),中心点(0.5,0.8)适用于(0.5,0.7)
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)
}
答案 0 :(得分:0)
试试这个
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)
}