如何从UIImageView

时间:2017-12-04 05:13:47

标签: ios objective-c uiimageview uiimage uicolor

我有一个类似于绘图板的屏幕 - 你选择一种颜色然后当你在视图上涂鸦时会有画的东西。我需要一个更好的橡皮擦,然后是我现在拥有的橡皮擦。如果我只是将我的橡皮擦设置为[UIColor clearColor],则会出现擦除的情况..尽管如此,我的手指绘图下面有一个绘图,它是从一个像wacom / stylus pad一样的硬件处理的。如果我在"删除" (使用clearColor)有一个alpha差异......我手指画下面的图层......我提供了一些截图..

enter image description here

你会注意到白线上的小灰色涂鸦。它们被删除 - 我需要这不是不透明.6 ClearColor - 我需要完全为0.任何想法?

这是我触动的代码:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    mouseSwiped = YES;
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self];

    UIGraphicsBeginImageContext(self.frame.size);

    [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 30.0 );

    CGFloat* components = CGColorGetComponents(_strokeColor.CGColor);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), components[0], components[1], components[2], 1);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

    CGContextStrokePath(UIGraphicsGetCurrentContext());
    self.image = UIGraphicsGetImageFromCurrentImageContext();

    [self setAlpha: .6];

        UIGraphicsEndImageContext();

    lastPoint = currentPoint;


}

0 个答案:

没有答案