擦除不工作
问题描述:
我绘制线条和任何形状,我想,但在擦除它不工作时,擦除不工作
对于图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();
同时删除我改变混合模式清晰,即使它不工作
,但不工作,请帮我
答
擦除u必须采取trasferent图像视图 和使用CGContextSetBlendMode(背景下,kCGBlendModeClear); 其正在为我工作...