I am trying to take a picture from a camera and overlay the image from a UIButton — which has been moved/rotated/scaled to some place on the screen.
The code below rotates the image properly but does not place it at the proper X,Y coordinates.
- (UIImage*)dumpOverlayViewToImage {
CGSize imageSize = self.cameraOverlayView.bounds.size;
UIGraphicsBeginImageContext(imageSize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, self.button.frame.origin.x, self.button.frame.origin.y);
CGContextConcatCTM(ctx, self.button.transform);
[self.button.imageView.image drawAtPoint:CGPointMake(0,0)];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
Help would be greatly appreciated.
If you are on a device with a retina display, you probably need to take that into account. The easiest way in this case should be to use this instead of
UIGraphicsBeginImageContext: