This routine returns nil in OSX 10.13.2 Beta but not in a playground. Don't have an older OS to test with at the moment.
func getImage(_ url: CFURL) -> CGImage? {
let sourceOptions = [
kCGImageSourceShouldAllowFloat as String: kCFBooleanTrue as NSNumber
] as CFDictionary
guard let imageSource = CGImageSourceCreateWithURL(url, sourceOptions) else { return nil }
guard let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else {
let imageSourceStatus = CGImageSourceGetStatus(imageSource)
Swift.print("image nil, Image Source Status = \(imageSourceStatus)")
return nil
}
return image
}
imageSource is non-nil, but image is nil. The console message is "Image Source Status = CGImageSourceStatus", which is not one of the valid enum values.
Tried with both Swift 3.2 and Swift 4.0. The Dictionary arg in CGImageSourceCreateWithURL can be set to nil; nothing changes.
The correct frameworks are in the project (although it linked without them, so I'm not sure they matter.) Did "import ImageIO" but it built without it, so again I'm not sure in matters.
The URL is absolutely a valid file URL -- like I said, this works in the playground, and I've tried a number of different files and file types (tiff, jpg and png).
Any ideas?