【问题标题】:image zoom, scroll view, crop图像缩放、滚动视图、裁剪
【发布时间】:2012-06-26 10:17:39
【问题描述】:

我只是通过将 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;    
}

【问题讨论】:

标签: iphone ios image scrollbar


【解决方案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);

} 

这可能有助于您裁剪图像。

【讨论】:

    猜你喜欢
    • 2011-01-30
    • 2016-08-29
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多