gpt4 book ai didi

iphone - 图像缩放、 ScrollView 、裁剪

转载 作者:行者123 更新时间:2023-11-29 04:34:47 30 4
gpt4 key购买 nike

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

ScrollView 委托(delegate)方法是

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

最佳答案

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

}

这可以帮助您裁剪图像。

关于iphone - 图像缩放、 ScrollView 、裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11205184/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com