1

I have an unusual requirement as drawn in the image below

enter image description here

Explanation:

(A) - Its an UIImageView control with pinch gesture added on it, that allows it to zoom

(B) - Normally user starts zooming from the area

(C) - The Cropping overlay, that allows to determine the area to be cropped.

Requirement

When (B) is zoomed (C) should change its area accordingly such as the zoomed part is always inside the cropped area without changing its shape.

Note I don't want to use scollview for this purpose, because I have other things to be implemented on it. Any help will be awesome.

Thanks.

iphonic
  • 12,615
  • 7
  • 60
  • 107

1 Answers1

1

I will not be baking the complete code for you here. Because this is a very simple stuff. However, I will give some helpful markers of how to do it.

  1. Calculate the aspect-fit rectangle of a the image in your main display view and place the image there.
  2. Add a zoomable view over your main display.
  3. Once the user is done zooming or de-zooming the view, find out the 4 corners of the zoomed view by combining it with its current zoomScale.
  4. Map these 4 corners on the actual image and then save the pixels falling in between these corners as an another image.
  5. The saved image is your required cropped image.
CodenameLambda1
  • 1,299
  • 7
  • 17
  • You mean to say don't zoom the image, but zoom the handles and then apply zoom on the actual image ? – iphonic Feb 13 '14 at 09:34
  • yes, when you zoom the view, you can get the frame of it, and then map this frame on the actual image. However, you will have to take the aspect fit of the image in account. – CodenameLambda1 Feb 13 '14 at 09:45