Problems creating animated gif in Swift

I'm trying to create an animated gif from an array of 4 elements UIImage

in Swift, but it currently only stores the first frame.

let url = NSURL(fileURLWithPath: photosDirectory)?.URLByAppendingPathComponent(filename())

if let url = url {
    let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
    let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 0.125]]
    let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, photos.count, nil)

    CGImageDestinationSetProperties(destination, fileProperties)

    for photo in photos {
        CGImageDestinationAddImage(destination, photo.CGImage, gifProperties)
    }

    return CGImageDestinationFinalize(destination)
}
else {
    return false
}

      

photos

- this array UIImages

filename()

just returns a string like20150805.gif

It returns true, but only the first frame is in the gif

+3


source to share


1 answer


kCGImagePropertyGIFDelayTime must be a non-double float.



try setting 0.125f instead of 0.125

+2


source







All Articles