Ich möchte ein UIImage aus einem Array von mehreren UIBezierPaths in Swift erstellen.Erstellen Sie ein UIImage aus Uibezierpath-Array in Swift
Ich habe versucht, den folgenden Code:
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
}
Das Ergebnis ist ein leeres Bild.
Kann mir jemand erklären, was ich falsch mache? Vielen Dank!
Fügen Sie diese Pfade zum Layer der Ansicht hinzu? – EridB
@EridB Nein. Ich möchte sie nicht zum Layer der Ansicht hinzufügen –
Kannst du bitte ein konkretes Beispiel für '[UIBezierPath]' Array anfügen? –