0

I'm presenting a popover from a button, in the popover users can make a drawing. I'd like to capture this drawing as a UIImage.

At the moment the drawing is a simple line drawing using UIBezierPath, similar to this tutorial: http://soulwithmobiletechnology.blogspot.com/2011/05/uibezierpath-tutorial-for-iphone-sdk-40.html

Thanks in advance for the help!

naudecruywagen
  • 378
  • 3
  • 8
  • 3
    http://stackoverflow.com/questions/1112947/how-to-create-a-uiimage-from-the-current-graphics-context – NeverBe Feb 18 '12 at 13:00
  • Thanks! I got it working. I couldn't find renderInContext, needed to add the import #import . The post steered me in the right direction – naudecruywagen Feb 19 '12 at 08:04

2 Answers2

0

If someone else comes across this. If you can't find renderInContext just #import <QuartzCore/QuartzCore.h>

naudecruywagen
  • 378
  • 3
  • 8
0

for an actual copy paste solution:

#import <QuartzCore/QuartzCore.h>

- (UIImage*) screenShot {

UIGraphicsBeginImageContext(_view.bounds.size);
[_view.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); //renders view to an image
UIGraphicsEndImageContext();

return viewImage;

}
Fonix
  • 11,447
  • 3
  • 45
  • 74