0

我只是通过将 imageView 放在 ScrollView 上来缩放图片。我想裁剪图像部分,它显示在 imageView 中(缩放后)并保存为新图像。

谢谢

代码在这里

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];

并且滚动视图委托方法是

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{    
    return self.imageView;    
}
4

1 回答 1

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);

} 

这可以帮助你裁剪图像。

于 2012-09-10T11:25:27.290 回答