我们如何使用swift以六边形裁剪方形图像。我想使用方形图像和裁剪/剪辑成六边形。例如。 Instagram的个人资料图片(但在六角形而不是圆形)在swift中
答案 0 :(得分:1)
您需要创建形状并将其另存为图像,然后执行图像蒙版。这是我用来做同样事情的代码的一部分,但是你需要创建自己的大小和rect变量。希望这可以帮助。
UIGraphicsBeginImageContext(size)
UIImage(CGImage: originalImage!).drawInRect(rect)
maskImage.drawInRect(rect, blendMode: CGBlendMode.DestinationIn, alpha: 1.0)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imageView.image = newImage