gizmodo gizmodo - 1 year ago 150
Swift Question

CGImageSource to CGImage?

I got this following code that access a PHAsset. I need to pass a CGImage out of this:

let imageManager = PHImageManager.defaultManager()
imageManager.requestImageDataForAsset(self.asset!, options: nil, resultHandler:{
(data, responseString, imageOriet, info) -> Void in
let imageData: NSData = data!
if let imageSource = CGImageSourceCreateWithData(imageData, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary

//How do I create a CGImage now?


I need to extract a CGImage out of this. Having trouble getting there...

Answer Source

Once you have the image source you can create an image using CGImageSourceCreateImageAtIndex:

let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download