Want to add manual erasing option in ipad painting application by Quartz

后端 未结 2 820
栀梦
栀梦 2020-12-04 04:16

I am working on a painting application using Quartz 2D for ipad. Now I want to add an eraser option so that user can manually erase portion of his drawn line with touch.I ha

2条回答
  •  执笔经年
    2020-12-04 04:50

    if(erase)
        {
            UITouch *touch = [touches anyObject];
            CGPoint currentTouch = [touch locationInView:extraImageVw];
    
            CGFloat brushSize;
            if (isEraser)
            {
                brushSize=25.0;
            }
            else
            {
                brushSize=25.0;
            }
            CGColorRef strokeColor = [UIColor whiteColor].CGColor;
    
            UIGraphicsBeginImageContext(extraImageVw.frame.size);
    
            CGContextRef context = UIGraphicsGetCurrentContext();
            [extraImageVw.image drawInRect:CGRectMake(0, 0, extraImageVw.frame.size.width, extraImageVw.frame.size.height)];
            CGContextSetLineCap(context, kCGLineCapRound);
            CGContextSetLineWidth(context, brushSize);
            if (isEraser) {
                CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:fullPathToFile]].CGColor);
            }
            else
            {
                CGContextSetStrokeColorWithColor(context, strokeColor);
                CGContextSetBlendMode(context, kCGBlendModeClear);
            }
            CGContextSaveGState(UIGraphicsGetCurrentContext());
            CGContextBeginPath(context);
            CGContextMoveToPoint(context, Lastpoint.x, Lastpoint.y);
            CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
            CGContextStrokePath(context);
            extraImageVw.image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
    
            Lastpoint = [touch locationInView:extraImageVw];
    
    
        }
    

提交回复
热议问题