是线程1:信号SIGABRT始终是连接问题(cgimagedestinationfinalize)

时间:2017-03-12 21:38:49

标签: swift cgimage

使用此块,我的应用程序每次尝试

时都会崩溃
CGImageDestinationFinalize(gifDest!)

func createGIF(with images: [CGImage], data: Data, loopCount: Int, frameDelay: Double) -> Data {
    print("()createGIF.HandHistoryTableVC")
    let gifDest = CGImageDestinationCreateWithData(data as! CFMutableData, kUTTypeGIF, images.count, nil)
    let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
    CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
    let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
    for img in images {
        CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
    }
    print("GIF in Progress")
    CGImageDestinationFinalize(gifDest!)
    print("gifMade")
    return data;
}

错误报告

enter image description here 我迷失了这次事故的原因。关于“线程1:信号SIGABRT”的所有研究似乎都说这是一个连接问题,但如果我注释掉CGImageDestinationFinalize()

我的整个应用程序都可以正常工作

1 个答案:

答案 0 :(得分:0)

func createGIF(with images: [CGImage], data: CFMutableData, loopCount: Int, frameDelay: Double) -> Data {
    print("()createGIF.HandHistoryTableVC")
    let gifDest = CGImageDestinationCreateWithData(data, kUTTypeGIF, images.count, nil)
    let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
    CGImageDestinationSetProperties(gifDest!, fileProperties as CFDictionary?)
    let frameProperties = [(kCGImagePropertyGIFDictionary as String): [(kCGImagePropertyGIFDelayTime as String): frameDelay]]
    for img in images {
        CGImageDestinationAddImage(gifDest!, img, frameProperties as CFDictionary?)
    }
    print("GIF in Progress")
    CGImageDestinationFinalize(gifDest!)
    print("gifMade")
    return data as Data;
}

使用CFMutableData初始化程序

CFDataCreateMutable(kCFAllocatorDefault, 0)

解决了这个问题。