将图像缩放到1/4大小(swift3)

时间:2017-03-22 14:50:28

标签: ios swift3 uiimageview scale uibezierpath

我正在尝试将myPicture缩放到更小的尺寸。我试图使它成为当前大小的1/4。使用bezierPath测试缩放图像的效果。理想情况下,我希望我的图片以1/4的采购当前尺寸显示在左下方。

import UIKit



   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://a248.e.akamai.net/secure.meetupstatic.com/photos/member/5/3/5/e/highres_260901342.jpeg")!))!

  let iv = UIImageView(image: myPicture)

   let bezierPath = UIBezierPath()
 bezierPath.move(to: iv.center)
 bezierPath.addLine(to: CGPoint(x: iv.frame.maxY, 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)

代码输出此图像。 enter image description here

0 个答案:

没有答案