我最近在创建一个Gif时遇到了一个问题,如果它的颜色太大就会丢失.但是感谢SO的帮助,有人能够帮我找到一个工作并创建我自己的颜色图.
以前的问题... 保存动画Gif时iOS颜色不正确
这在iOS 11中运行良好.我在文档中找不到任何改变的东西,并且会使它不再起作用.我发现如果我删除了kCGImagePropertyGIFImageColorMap一个Gif生成但它有原始问题,如果gif像我之前的问题一样变大,颜色会丢失.这是有意义的,因为这是为了解决这个问题而添加的.
疑似问题......
func createGifFromImage(_ image: UIImage) -> URL{
let fileProperties: [CFString: CFDictionary] = [kCGImagePropertyGIFDictionary: [
kCGImagePropertyGIFHasGlobalColorMap: false as NSNumber] as CFDictionary]
let documentsDirectoryPath = "file://\(NSTemporaryDirectory())"
if let documentsDirectoryURL = URL(string: documentsDirectoryPath){
let fileURL = documentsDirectoryURL.appendingPathComponent("test.gif")
let destination = CGImageDestinationCreateWithURL(fileURL as CFURL, kUTTypeGIF, 1, nil)!
CGImageDestinationSetProperties(destination, fileProperties as CFDictionary);
let colorMap = image.getColorMap()
print("ColorMap \(colorMap.exported as NSData)")
let frameProperties: [String: AnyObject] = [
String(kCGImagePropertyGIFImageColorMap): colorMap.exported as NSData
]
let properties: [String: AnyObject] = [
String(kCGImagePropertyGIFDictionary): …Run Code Online (Sandbox Code Playgroud) 我对带有类型的变量提出了挑战UnsafeMutablePointer<UInt8>.
我有这个工作代码来分配并设置为零UInt8在Swift中的所有数组.
var bits = UnsafeMutablePointer<UInt8>(calloc(width * height, 8))
问题是我想在不使用calloc方法的情况下这样做.我有这个代码来分配数组
var bits = UnsafeMutablePointer<UInt8>.alloc(width * height)
但我找不到一个方法来设置所有内存为零.
我知道我可以做到这一点,但我认为这不是最好的方法.
for index in 0..< (width * height) {
bits[index] = 0
}
Run Code Online (Sandbox Code Playgroud)