1
我想从Swift中的多个UIBezierPath数组创建UIImage。在Swift中从Uibezierpath数组创建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
@EridB号我不想将它们添加到视图的图层 –
可以附加'[UIBezierPath]'阵列的具体示例吗? –