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]'陣列的具體示例嗎? –