Created
May 4, 2018 08:37
-
-
Save bumaociyuan/3b4d3da7144ae5baa28cd24b506d83ae to your computer and use it in GitHub Desktop.
Get first frame of gif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
// first frame of gif | |
class func firstFrame(gif url: URL) -> UIImage? { | |
guard let data = try? Data(contentsOf: url) as CFData else { | |
return nil | |
} | |
guard let source = CGImageSourceCreateWithData(data, nil) else { | |
return nil | |
} | |
guard let cgimage = CGImageSourceCreateImageAtIndex(source, 0, nil) else { | |
return nil | |
} | |
let image = UIImage(cgImage: cgimage) | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment