2014-01-09 1 views
0

Я работаю с графическим приложением, в котором я рисую внутри CGlayers, а затем рисую контекст графиков, но рисунок становится размытым.Получение размытия при рисовании в Cglayer

Вот мой код

- (void)drawRect:(CGRect)rect 
{ 
CGContextRef context = UIGraphicsGetCurrentContext();//Get a reference to current context(The context to draw) 
      NSLog(@"Size1%@", NSStringFromCGRect(self.bounds)); 

      if(self.currentDrawingLayer == nil) 
      { 
       self.currentDrawingLayer = CGLayerCreateWithContext(context, self.bounds.size, NULL); 
      } 


      CGPoint mid1 = midPoint(m_previousPoint1, m_previousPoint2); 
      CGPoint mid2 = midPoint(m_currentPoint, m_previousPoint1); 


      CGContextRef layerContext = CGLayerGetContext(self.currentDrawingLayer); 
      // UIGraphicsBeginImageContextWithOptions(self.bounds.size,YES,0.0); 

      CGContextSetLineCap(layerContext, kCGLineCapRound); 
      CGContextSetBlendMode(layerContext, kCGBlendModeNormal); 
      CGContextSetLineJoin(layerContext, kCGLineJoinRound); 
      CGContextSetLineWidth(layerContext, self.lineWidth); 
      CGContextSetStrokeColorWithColor(layerContext, self.lineColor.CGColor); 
      CGContextSetShouldAntialias(layerContext, YES); 
      CGContextSetAllowsAntialiasing(layerContext, YES); 
      CGContextSetAlpha(layerContext, self.lineAlpha); 
      CGContextSetFlatness(layerContext, 1.0f); 
      CGContextBeginPath(layerContext); 
      CGContextMoveToPoint(layerContext, mid1.x, mid1.y);//Position the current point 
      CGContextAddQuadCurveToPoint(layerContext, m_previousPoint1.x, m_previousPoint1.y, mid2.x, mid2.y); 
      CGContextStrokePath(layerContext);//paints(fills) the line along the current path. 

      CGContextDrawLayerInRect(context, self.bounds, self.currentDrawingLayer); 
} 

я Blurr мазки с этим кодом, согласно документации, всякий раз, когда мы создаем CGlayer с graphicsContext, они говорят, что это обеспечит разрешение устройства, но тогда почему Я получаю размытие линий.

Вот образ размытия линий enter image description here

С уважением Ранджит

ответ

3

Заменитель это в коде, где вы создаете CGLayer:

if(self.currentDrawingLayer == nil) 
{ 
    CGFloat scale = self.contentScaleFactor; 
    CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale); 
    CGLayerRef layer = CGLayerCreateWithContext(context, bounds.size, NULL); 
    CGContextRef layerContext = CGLayerGetContext(layer); 
    CGContextScaleCTM(layerContext, scale, scale); 
    self.currentDrawingLayer = layer; 
} 
+0

Спасибо, это работает отлично. Не могли бы вы посмотреть на этот вопрос http://stackoverflow.com/questions/21027788/drawing-multiple-images-with-different-size-on-cglayer – Ranjit

+0

Здравствуйте @Gavin, пожалуйста, посмотрите на это http://stackoverflow.com/questions/21438586/undo-redo-for-drawing-in-ios Мне нужна ваша помощь – Ranjit

+0

Здравствуйте @Gavin, пожалуйста, посмотрите на это http://stackoverflow.com/questions/21906687/getting-pixelated-strokes-while-drawing- uibezeirpath-in-cglayer – Ranjit