I’m trying to build a simple photo crop utility where user can touch and select the picture boundary. I need the exact touch coordinates w.r.t the image.
When I use
CGImageRef imageRef = [staticBG.image CGImage];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[self view]];
y3=location.y;
x3=location.x;
the coordinates (x3,y3) comes in absolute scale and is not useful for handling imageRef.
I tried using
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:staticBG];
but still the coordinates do not quite match up.
Please help.
I don’t think we need exact coordinates from the user touch, but to crop the image I will :
crop. The maskView has a exact frame that can be easily known.
touchesBeganandtouchesMoved. Whilethe user touch moves, move the maskView as well (change maskView’s
frame). In this step, we need to decide that which vertex of the
maskView is the closest to the
Pointthat user touched — leftTop,rightTop, leftBottom or rightBottom.
touchesEnded, we use the maskView’s frame to crop the image.Here, the coordinates is exact enough. Notice that we need to change
the maskView’s frame for image’s coordinate system.
Hope helps. 🙂