Presenting an image cropping interface

Posted by wkw on Stack Overflow See other posts from Stack Overflow or by wkw
Published on 2010-04-21T02:32:12Z Indexed on 2010/04/21 2:33 UTC
Read the original article Hit count: 324

Filed under:

I'm trying to engineer a UI for cropping images in iphone OS and suspect I'm going about things the hard way. My goal is pretty much what the Tapbots duo have done with Pastebot. In that app, they dim the source image but provide a movable and resizable cropping view and the image you're cropping is in a zoomable scrollview; when you resize or move the underlying image, the cropping view adjusts appropriately.

I mocked up a composite image which will give a sense of the design I'm after, along with how I presently have my view hierarchy setup, viewable here

The approach I've started with is the following: UIImageView with the image to crop is in a scrollview, a plain UIView with black fill and suitable transparency/alpha setting is added in front of the imageview. I then use a custom UIView which is a sibling to the scrollview at a higher level, which implements the drawRect: method and for the most part calls CGImageCreateWithImageInRect to get the portion of the image's bitmap that matches the position of the cropping view and draws that to the CGContext.

in the viewcontroller I'm using the UIScrollViewDelegate methods to track scrolling and passing those changes to the custom cropping UIView so it stays in sync with the scroll contentOffset. That much is finally working. But trying to keep in sync as the scrollview zoomScale changes is when I figured I should ask for help.

Looking for suggestions or guidance. My initial approach just seems like more work than is required.

Could this be done with a masking layer in the ImageView? And if so, how would I setup the tracking for moving and resizing the cropping rect? My experience working with layers is non-nil, but very limited thus far.

© Stack Overflow or respective owner

Related posts about iphone