[英]iOS Zoom/Distort a particular part of the image using CIFilter
The use case is to detect something in an image and zoom\/distort-outward it as in you are looking through a magnifying glass.用例是检测图像中的某些内容并向外缩放\/扭曲它,就像您通过放大镜查看一样。
Now I know the points where to zoom in but I need a CIFilter which can do the same.现在我知道放大的点,但我需要一个可以做同样事情的 CIFilter。
Tried CIHoleDistortion<\/a> but it did not work.尝试过CIHoleDistortion<\/a>但它没有用。 The documentation seems to be fine to me and it should work but it only creates a black hole and the area around it is distorted.该文档对我来说似乎很好,它应该可以工作,但它只会创建一个黑洞并且它周围的区域是扭曲的。
let distortion = CIFilter(name: "CIHoleDistortion")
distortion.setValue(sourceImage, forKey: kCIInputImageKey)
distortion.setValue(CIVector.init(cgPoint: CGPoint.init(x: 200, y: 200)), forKey: "inputCenter")
distortion.setValue(NSNumber.init(value: 100), forKey: "inputRadius")
CIBumpDistortion as mentioned by Frank above, but the scale
parameter actually works as follows: scale < 0
-> concave;上面 Frank 提到的CIBumpDistortion ,但scale
参数实际上是这样工作的: scale < 0
-> concave; scale > 0
-> convex. scale > 0
-> 凸的。
Another (and maybe better) option is to use CIGlassLozenge
filter:另一个(也许更好)的选择是使用CIGlassLozenge
过滤器:
inputRefraction
to something slightly larger than 1 (eg 1.06)将inputRefraction
设置为略大于 1 的值(例如 1.06)inputPoint0
and inputPoint1
with the coordinate of the zoom point将inputPoint0
和inputPoint1
都与缩放点的坐标对齐If you want to play with this filter (and any other out of 250 CIFilters) in real time check this app out: https://apps.apple.com/us/app/filter-magic/id1594986951如果您想实时使用此过滤器(以及 250 个 CIFilter 中的任何其他过滤器),请查看此应用: https ://apps.apple.com/us/app/filter-magic/id1594986951
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.