Reputation: 1470
Please help.
No one seems to have a successful working answer to the following:
I get an image from the iPhone camera using UIImagePickerController. When taking the image there is an overlay present. The overlay is simply a subclassed UIImageView with various gestures attached.
When I take the image, how do I add the overlay to the image in precisely where it is on the device screen?
Any help much appreciated,
LB
Upvotes: 0
Views: 196
Reputation: 4164
I'm writing this away from xcode, so it may need tweaks...
Create a UIView class with UIImage properties, picture & overlay, & call it something like compositorView. From the didFinishPickingMediaWithInfo: method in your UIImagePickerController delegate, set the picture property of compositorView to the photo you've just taken, & the overlay property to whatever image you're using. Then ask compositorView for its composedImage, & that should be it...
(You'll need the QuartzCore framework)
@synthesize picture = _picture;
@synthesize overlay = _overlay;
-(void)drawRect:(CGRect)rect
{
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
CGRect frame = CGRectMake(0, 0, width, height);
[_picture drawInRect:frame];
[_overlay drawInRect:frame];
}
-(UIImage *)composedImage
{
CGSize pageSize = self.frame.size;
UIGraphicsBeginImageContextWithOptions(pageSize, NO, 2.0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
Upvotes: 3