CGBitmapContextCreate-Fehler mit swift
Ich versuche zu erstellen CGContext in swift. Es kompiliert wird, wirft aber einen Fehler zur Laufzeit.
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceRGB()
let context:CGContext = CGBitmapContextCreate(nil, 20, 20, 8, 0, colorSpace, CGBitmapInfo.AlphaInfoMask)
CGColorSpaceRelease(colorSpace);
....
Und der Fehler ist:
Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; unrecognized; 96 bytes/row.
fatal error: Can't unwrap Optional.None
InformationsquelleAutor der Frage loopmasta | 2014-06-08
Du musst angemeldet sein, um einen Kommentar abzugeben.
Nur im Fall, dass jemand mit den gleichen problem. Das snippet unten funktioniert endlich.
Er generiert eine 32-bit-RGBA Rahmen in swift
InformationsquelleAutor der Antwort loopmasta
Aktualisiert Swift 3:
InformationsquelleAutor der Antwort Echelon
In Swift 2.1 kann man auf den Feldern richtig sind, und selbst ODER zusammen:
Menge "rawValue" gespielt wird 🙂
Brauchen Sie nicht einmal zu trennen, die bitmapInfo-und tun können, einen one-liner:
InformationsquelleAutor der Antwort Graham Perks
Hatte ich einige Probleme in Swift 1.2 mit
UInt
jetzt bin ich mitInt
- und es funktioniert.Dieses Beispiel zeigt, wie der Umwandlung eines Bildes in ein Graustufenbild.
InformationsquelleAutor der Antwort Miralem Cebic
Vorgeschlagenen Weise kompatibel mit Xcode 8.3 und Xcode 9 unterstützt Swift 3 und Swift 4
InformationsquelleAutor der Antwort abdullahselek
Swift 2.2:
InformationsquelleAutor der Antwort Sam Soffes
CGBitmapInfo.AlphaInfoMask ist keine gültige bitmap-info.
Versuchen Sie CGBitmapInfo.AlphaLast oder CGBitmapInfo.AlphaFirst.
InformationsquelleAutor der Antwort Goz