0
我繪製線條和任何形狀,我想,但在擦除它不工作時,擦除不工作
對於圖i用下面的代碼
在這個代碼我通過使用石英芯
繪製previousPoint1 = [touch previousLocationInView:m_img];
previousPoint2 = [touch previousLocationInView:m_img];
currentPoint = [touch locationInView:m_img];
//
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:m_img];
currentPoint = [touch locationInView:m_img];
// calculate mid point
CGPoint mid1 = [self midPoint:previousPoint1 :previousPoint2];
CGPoint mid2 =[self midPoint:currentPoint :previousPoint1];
UIGraphicsBeginImageContext(m_img.frame.size);
[m_img.image drawInRect:CGRectMake(0, 0, m_img.frame.size.width, m_img.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, mid1.x, mid1.y);
// Use QuadCurve is the key
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGBitmapContextGetColorSpace(context);
//CGContextSetStrokeColor(<#CGContextRef context#>, <#const CGFloat *components#>)
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context,m_width);
CGContextStrokePath(context);
m_img.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
和用於擦除圖i用下面的代碼
m_widthString=[userdefault valueForKey:@"EraserWidth"];
m_width=[m_widthString floatValue];
previousPoint1 = [touch previousLocationInView:m_img];
previousPoint2 = [touch previousLocationInView:m_img];
currentPoint = [touch locationInView:m_img];
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:m_img];
currentPoint = [touch locationInView:m_img];
// calculate mid point
CGPoint mid1 = [self midPoint:previousPoint1 :previousPoint2];
CGPoint mid2 =[self midPoint:currentPoint :previousPoint1];
UIGraphicsBeginImageContext(m_img.frame.size);
[m_img.image drawInRect:CGRectMake(0, 0, m_img.frame.size.width, m_img.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context,m_width);
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGContextDrawPath(context, kCGPathFillStroke);
m_img.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
同時刪除我改變混合模式清晰,即使它不工作
,但不工作,請幫我