0

I simply zoom the picture by placing imageView on ScrollView. i want to crop the image portion, which is showed in imageView (after zooming) and save as a new image.

thanks

code is here

CGRect frame = CGRectMake(0,0,190,210);

scroll = [[UIScrollView alloc] initWithFrame:frame];

scroll.contentSize = CGSizeMake(240, 260);

scroll.showsHorizontalScrollIndicator = YES;

scroll.showsVerticalScrollIndicator = YES;  

[scroll addSubview:imageView];

and the scrollview delegate method is

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{    
    return self.imageView;    
}
Pratyusha Terli
  • 2,343
  • 19
  • 31

1 Answers1

1
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
StartPoint = [touch locationInView:touch.view];

}

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// get touch event
UITouch *touch = [[event allTouches] anyObject];
EndPoint = [touch locationInView:touch.view];
[self finishedTouchInside];

}

 -(void)finishedTouchInside{

CGFloat width=EndPoint.x-StartPoint.x;
CGFloat hieght=EndPoint.y-StartPoint.y;
CGRect myImageRect = CGRectMake(StartPoint.x, StartPoint.y, width, hieght);
Img_Screen= [[UIImageView alloc] initWithFrame:myImageRect];

CGImageRef imageRef = CGImageCreateWithImageInRect([imgView.image CGImage], myImageRect);
// or use the UIImage wherever you like
UIImage *newImage =[UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

} 

this may help u to crop the Image.

Nookaraju
  • 1,668
  • 13
  • 24