objective-ciphoneuiimagecore-graphicsquartz-2d

How do I get UIImage from a CGContextRef?


I have a CGContextRef and I did my drawing stuff with the bitmap context.

Now, I would like to have a function call to get a UIImage for the CGContextRef. How do I do that?


Solution

  • Something like this :

    -(UIImage*)doImageOperation
    {
      // Do your stuff here
      CGImageRef imgRef = CGBitmapContextCreateImage(context);
      UIImage* img = [UIImage imageWithCGImage:imgRef];
      CGImageRelease(imgRef);
      CGContextRelease(context);
      return img;
    }