UIImageView -> UIScrollview, crop and clip scroll view cooridantes

Go To StackoverFlow.com

1

Can someone point me in the right direction. I've been searching around for this, but can't seem to find a clear answer. I have a UIScrollview thats 300x300 pixels. Inside that I have an UIImageView. The idea is to allow a user to grab a photo from their library, then pinch and zoom it within the 300x300 scrollview. Then save the view port as a new photo.

So far I have this...

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {

    UIImageView *insideImgView = [[UIImageView alloc] initWithImage:image];
    scroller.contentSize = CGSizeMake(image.size.width, image.size.height);
    scroller.maximumZoomScale = 4.0;
    scroller.minimumZoomScale = 0.0;
    scroller.clipsToBounds = YES;
    scroller.delegate = self;
    [self setSendImage:insideImgView];
    [scroller addSubview:insideImgView];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return sendImage;
}

This works fine. I can pull the image in and pinch and zoom. But now how do i get the zoom and coordinates to slice up the photo when the they are done?

2012-04-04 23:31
by Mike Jaffe
Using your own gestures inside the image view would be bette - Otium 2012-04-05 00:00
Thanks, Otium. I think you might be right. Tried using gestures right on the UIImage view. Works great. Thanks - Mike Jaffe 2012-04-05 03:01
No problem, glad to help : - Otium 2012-04-05 03:43
So I've got the pinch/zoom directly on the UIImageView now. But I'm still not clear on how to save the current zoom/move state? Is there a "one shot" way with UIImageView? Or do I need get coordinates, zoom ratio..etc - Mike Jaffe 2012-04-05 16:38
Capture a snapshot of the UIImageView using CoreGraphic - Otium 2012-04-05 19:12
hi @MikeJaffe I need exactly same thing. How did you end up solving your problem - BObereder 2013-02-09 19:24
I used this solution. Worked perfectly. http://codefuel.wordpress.com/2011/04/22/image-cropping-from-a-uiscrollview - Mike Jaffe 2013-02-10 02:10


1

Exporting a view's content into an image is pretty simple.

Try using the answer by St3fan in this post: Get a PDF/PNG as output from a UIWebView or UIView.

2012-04-04 23:45
by Bojan Dimovski
Ads