ios - 如何将图像拉伸(stretch)成自定义形状(swift3)
<p><p> <a href="/image/OSJNG.png" rel="noreferrer noopener nofollow"><img src="/image/OSJNG.png" alt="enter image description here"/></a> </p>
<p>下面的代码列表裁剪图像。我希望图像被转换/拉伸(stretch)而不是裁剪成形状。所有图像内容仍然在转换后的图片中。它看起来会有所不同。 </p>
<pre><code>extension UIImageView {
func addMask(_ bezierPath: UIBezierPath) {
let pathMask = CAShapeLayer()
pathMask.path = bezierPath.cgPath
layer.mask = pathMask
}
}
let myPicture = UIImage(data: try! Data(contentsOf: URL(string:"https://scontent-iad3-1.xx.fbcdn.net/v/t31.0-8/14196150_10207770295835716_3510332720585393213_o.jpg?oh=fdb525410602f40f4735991b713e9c50&oe=596688E5")!))!
let iv = UIImageView(image: myPicture)
let bezierPath = UIBezierPath()
bezierPath.move(to: iv.center)
bezierPath.addLine(to: CGPoint(x: iv.frame.maxX, y: 0))
bezierPath.addLine(to: CGPoint(x: iv.frame.maxX, y: iv.frame.maxY))
bezierPath.addLine(to: CGPoint(x: 0, y: iv.frame.maxY))
bezierPath.addLine(to: .zero)
bezierPath.close()
iv.addMask(bezierPath)
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>看看这个帖子:</p>
<p> <a href="https://stackoverflow.com/questions/20863904/warp-bend-effect-on-a-uiview/20974947#20974947" rel="noreferrer noopener nofollow">Warp \ bend effect on a UIView?</a> </p>
<p>讨论了几种解决方案,包括使用核心图像过滤器,或使用 OpenGL 构建您自己的“网格扭曲”。 </p>
<p>还有<a href="https://github.com/BradLarson/GPUImage" rel="noreferrer noopener nofollow"><strong>Brad Larson open source framework GPUImage on Github</strong></a> .您也许可以使用该框架构建一个过滤器来做您想做的事情。</p></p>
<p style="font-size: 20px;">关于ios - 如何将图像拉伸(stretch)成自定义形状(swift3),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42861078/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42861078/
</a>
</p>
页:
[1]