Last active
August 4, 2021 11:56
-
-
Save varun04/11795320a0c40e7ee7709b73134b2848 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| func createFrameImage(at index: Int, downsamplingLevel: DownSamplingLevel = .default, decodingOptions: DecodingOptions = .default) -> CGImage? { | |
| guard index < frameCount else { | |
| return nil | |
| } | |
| let image: CGImage? | |
| let options: CFDictionary | |
| switch decodingOptions.mode { | |
| case .asynchronous: | |
| // No need to consider the down sampling when comparing the image native size with sizeForDrawing. | |
| guard var size = frameSize(at: index) else { | |
| return nil | |
| } | |
| if let sizeForDrawing = decodingOptions.sizeForDrawing { | |
| // Choose the smaller one. | |
| if sizeForDrawing.width * sizeForDrawing.height < size.width * size.height { | |
| size = sizeForDrawing | |
| } | |
| } | |
| options = imageSourceAsyncOptions(sizeForDrawing: size, donwsamplingLevel: downsamplingLevel) | |
| image = CGImageSourceCreateThumbnailAtIndex(imageSource, index, options) | |
| case .synchronous: | |
| options = imageSourceOptions(with: downsamplingLevel) | |
| image = CGImageSourceCreateImageAtIndex(imageSource, index, options) | |
| } | |
| return image | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment