iPhone - How do you make a resizable rectangle for cropping images?

0SX picture 0SX · Dec 28, 2009 · Viewed 7.1k times · Source

I'm having a trouble making a re-sizable rectangle for cropping my images. I'm trying to achieve something like this picture:

http://img192.imageshack.us/img192/8930/customcropbox.jpg

Well, the only problem is I have no clue where to actually start. I need some advice to how I can achieve this effect of cropping. What documentation should I read up on? Core Graphics or Quartz 2d? Both? I've been coding for the iPhone since it's release date but I've never actually used core graphics and etc. Any help or advice would be much appreciated. I'll throw my code up here as I progress to show how it's done when I achieve it. :-) Also, this rectangular box is moveable across the screen in a UIImageView which just makes it more interesting. Thanks for the help and I look forward to achieving this goal.

Answer

Ben Gottlieb picture Ben Gottlieb · Dec 28, 2009

Quartz is the 'marketing term' for Core Graphics, and that's where you should start. You'll want to use a UIView (full custom drawing in -drawRect:), trap and track its touches, and then draw the result. You can get the current Graphics Context using UIGraphicsGetCurrentContext(). That should be enough to get you started!