2012-07-13 35 views
2
绘制模糊笔画

我在iOS设备进行绘图工作,我有我的代码工作,绘图工作正常,现在我已经实现了撤销和重做功能,但正在发生的事情是,假设我得出两点线,然后按撤消按钮,然后第一条线绘制得到模糊,,我不明白为什么发生,下面是我的撤消代码。获得,而在iOS的

-

(void)redrawLine 
{ 
    UIGraphicsBeginImageContext(self.bounds.size); 
    [self.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    NSDictionary *lineInfo = [lineArray lastObject]; 
    curImage = (UIImage*)[lineInfo valueForKey:@"IMAGE"]; 
    UIGraphicsEndImageContext(); 
    [self setNeedsDisplayInRect:self.bounds]; 
    [self setNeedsDisplay]; 
} 



-(void)undoButtonClicked 
{ 
    if([lineArray count]>0){ 
     NSMutableArray *_line=[lineArray lastObject]; 
     [bufferArray addObject:[_line copy]]; 
     [lineArray removeLastObject]; 
     drawStep = UNDO; 
     [self redrawLine]; 
    } 

} 


- (void)drawRect:(CGRect)rect 
{ 

    switch (drawStep) { 
     case DRAW: 
     { 
      [curImage drawAtPoint:CGPointMake(0, 0)]; 
      CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
      CGPoint mid2 = midPoint(currentPoint, previousPoint1); 
      CGContextRef context = UIGraphicsGetCurrentContext(); 

      [self.layer renderInContext:context]; 
      CGContextMoveToPoint(context, mid1.x, mid1.y); 
      CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 
      CGContextSetLineCap(context, kCGLineCapButt); 
      CGContextSetLineWidth(context, self.lineWidth); 
      CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 
      CGContextSetAlpha(context, self.lineAlpha); 
      CGContextSetAllowsAntialiasing(context, YES); 
      CGContextStrokePath(context);    
      [super drawRect:rect]; 

     }   
     case UNDO: 
     { 
      [curImage drawInRect:self.bounds]; 
      break; 
     } 
} 

下面是当按下复原按钮,发生了什么图像

第一个图像是在点击之前undobutton和第二图像是在点击undobutton后

Before Undo Button clicked After Undo Button Clicked

关注 Ranji t

+0

朋友你好,有任何意见 – Ranjit 2012-07-13 08:46:24

回答

4

您致电UIGraphicsBeginImageContext指定位图的大小(以点为单位)。 320x480全屏显示),但在具有视网膜显示器的设备上,您需要一个像素大小的屏幕(即640x960)。

您应该可以拨打UIGraphicsBeginImageContextWithOptions并将scale设为0.0。从文档:

适用于位图的比例因子。如果您指定的值为0.0,则缩放系数将设置为设备主屏幕的缩放系数。

+0

嗨马丁非常感谢,它解决了问题,如何确定比例因子?而这个问题也是在iPod touch上(这是没有视网膜显示)。 – Ranjit 2012-07-13 09:15:36

+0

谢谢,伙计们,我有同样不想要的模糊,但是这个解决方案修复了它! – Borzh 2015-05-29 15:51:11

+0

巨大的帮助!没有怀疑这个!谢谢。 – 2016-12-08 11:07:55