【发布时间】:2016-09-12 13:29:12
【问题描述】:
我想在 Swift 中从多个 UIBezierPaths 的数组创建一个 UIImage。
我尝试了以下代码:
func convertPathsToImage(paths: [UIBezierPath]) -> UIImage{
let imageWidth: CGFloat = 200
let imageHeight: CGFloat = 200
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()!
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(nil, Int(imageWidth), Int(imageHeight), 8, 0, colorSpace, bitmapInfo.rawValue)
CGContextBeginPath(context);
UIColor.blackColor().set()
for path in paths{
path.stroke()
}
let newImageRef = CGBitmapContextCreateImage(context);
let newImage = UIImage(CGImage: newImageRef!)
return newImage
}
结果是一个空图像。
谁能解释我做错了什么?非常感谢!
【问题讨论】:
-
您是否将这些路径添加到视图层?
-
@EridB 不,我不想将它们添加到视图层
-
你能附上
[UIBezierPath]数组的具体例子吗? -
@ShadowOf 为什么会有帮助? UIBezierPaths 数组中有什么特别之处?无论如何我解决了这个问题,稍后会在这里发布我的答案。
标签: ios swift uiimage uibezierpath