CGImageSource to CGImage?

3.1k Views Asked by At

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...

1

There are 1 best solutions below

0
sbooth On BEST ANSWER

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

let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil)