gpt4 book ai didi

iphone - 从裁剪图像中删除不需要的区域

转载 作者:行者123 更新时间:2023-12-03 20:15:21 26 4
gpt4 key购买 nike

我正在研究通过触摸裁剪图像。为此,我使用 UIBezierPath

我可以裁剪掉选定的区域,但是不需要的区域(不在裁剪部分内)仍然占用空间。或者换句话说,我无法摆脱裁剪区域之外的区域。

那么,如何删除这个不需要/无用的区域?

这是我的代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIView *touchedView = [delegate viewForUseWithTool:self];
for (UITouch *touch in [event allTouches]) {
// remember the touch, and its original start point, for future
[trackingTouches addObject:touch];
CGPoint location = [touch locationInView:touchedView];
[startPoints addObject:[NSValue valueWithCGPoint:location]];
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineCapStyle = kCGLineCapRound;
[path moveToPoint:location];
[path setLineWidth:delegate.strokeWidth];
[path addLineToPoint:location];
[paths addObject:path];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in [event allTouches]) {
// make a line from the start point to the current point
NSUInteger touchIndex = [trackingTouches indexOfObject:touch];
// only if we actually remember the start of this touch...
if (touchIndex != NSNotFound) {
UIBezierPath *path = [paths objectAtIndex:touchIndex];
PathDrawingInfo *info = [PathDrawingInfo pathDrawingInfoWithPath:path fillColor:[UIColor clearColor] strokeColor:delegate.strokeColor];
[delegate addDrawable:info];
[trackingTouches removeObjectAtIndex:touchIndex];
[startPoints removeObjectAtIndex:touchIndex];
[paths removeObjectAtIndex:touchIndex];
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in [event allTouches]) {
// make a line from the start point to the current point
NSUInteger touchIndex = [trackingTouches indexOfObject:touch];
// only if we actually remember the start of this touch...
if (touchIndex != NSNotFound) {
UIBezierPath *path = [paths objectAtIndex:touchIndex];
PathDrawingInfo *info = [PathDrawingInfo pathDrawingInfoWithPath:path fillColor:[UIColor clearColor] strokeColor:delegate.strokeColor];
[delegate addDrawable:info];
[trackingTouches removeObjectAtIndex:touchIndex];
[startPoints removeObjectAtIndex:touchIndex];
[paths removeObjectAtIndex:touchIndex];
}
}
}

最佳答案

我可以按照 this answer 调整生成的图像大小。对于视网膜显示,我必须将裁剪矩形的大小加倍,并在 this answer 的帮助下检测到视网膜显示。 .

编辑

我找到了更好的解决方案。步骤如下:

  1. UIImage 转换为 UIImageView
  2. 关注this answer .

关于iphone - 从裁剪图像中删除不需要的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11242101/

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