I have an application having functionality for image clipping. The Functionality is I have three images :
- Main image - set as Background
- Overlay image - image set on Main image
- Pointer image - image that will move on touch
I want to remove the Overlay image on touch as i drag the Pointer image. After clipping Overlay image Main image should get visible.
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
// Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:imgPointer];
startLocation = pt;
[[imgPointer superview] bringSubviewToFront:imgPointer];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:imgPointer];
CGRect frame = [imgPointer frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[imgPointer setFrame:frame];
UIGraphicsBeginImageContext(imgPointer.frame.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect clippedRect = CGRectMake(0, 0, imgPointer.frame.size.width, imgPointer.frame.size.height);
CGContextClipToRect( currentContext, clippedRect);
CGRect drawRect = CGRectMake(imgPointer.frame.origin.x * -1,
imgPointer.frame.origin.y * -1,
imgOverlay.frame.size.width,
imgOverlay.frame.size.height);
//draw the image to our clipped context using our offset rect
CGContextDrawImage(currentContext, drawRect, imgOverlay.image.CGImage);
//pull the image from our cropped context
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
From using above code i am not able to clip Overlay image.
Thank you.