【问题标题】:Removing the unwanted area from cropped image从裁剪的图像中删除不需要的区域
【发布时间】:2012-06-29 19:45:23
【问题描述】:

我正在通过触摸裁剪图像。为此,我使用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];
        }
    }
}

【问题讨论】:

    标签: iphone crop uibezierpath


    【解决方案1】:

    我可以通过关注this answer 来调整生成图像的大小。 对于视网膜显示,我不得不将cropRect 的大小加倍,并且在this answer 的帮助下检测到了视网膜显示。

    编辑

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    相关资源
    最近更新 更多