我按照自己的意愿绘制线条和任何形状,但在擦除它时不起作用,
对于绘图,我使用了以下代码
在此代码中我使用石英核心
绘制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();
并且为了擦除绘图,我使用了以下代码
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();
擦除时我改变了混合模式,即使它不起作用
但是没有用,请帮帮我
答案 0 :(得分:0)