9

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

Gizmodo
  • 3,151
  • 7
  • 45
  • 92

1 Answers1

11

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

let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil)
sbooth
  • 16,646
  • 2
  • 55
  • 81