简体   繁体   English

iOS 使用 CIFilter 缩放/扭曲图像的特定部分

[英]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过滤器:

  1. Set inputRefraction to something slightly larger than 1 (eg 1.06)inputRefraction设置为略大于 1 的值(例如 1.06)
  2. Allign both inputPoint0 and inputPoint1 with the coordinate of the zoom pointinputPoint0inputPoint1都与缩放点的坐标对齐
  3. Play with the radius to get the desired effect.玩半径以获得所需的效果。 The attached example uses radius 1000.所附示例使用半径 1000。 在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM