47

I'm building an Iphone app that needs to convert a UIImage to a CGImageRef. I have no idea how to do this and would love some help. I have no background in working with images... :)

Tyler Wall
  • 3,747
  • 7
  • 37
  • 52

3 Answers3

110

It is as simple as image.CGImage where image is a UIImage object.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • 5
    Do note that the CGImage may not be exactly equivalent to the UIImage. In particular, watch out for `imageOrientation` being other than `UIImageOrientationUp`. – Anomie May 20 '11 at 04:02
  • 3
    Be aware of `image` could also be created from `CIImage` – zc246 Sep 07 '16 at 08:53
16
CGImageRef cgImage = [someImage CGImage];
Jason Coco
  • 77,985
  • 20
  • 184
  • 180
3

write folowing to get CGImage from UIImage: Suppose u have an UIImage object ex imageObject then,

CGImage imageRef = imageObject.CGImage
Duck
  • 34,902
  • 47
  • 248
  • 470
Satish Azad
  • 2,302
  • 1
  • 16
  • 35