在iOS中绘图时获得模糊描边

Ran*_*jit 2 cocoa-touch drawing core-graphics quartz-graphics 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;
        }
}
Run Code Online (Sandbox Code Playgroud)

下面是按下撤消按钮时发生的事情的图像

第一个图像是在单击undobutton之前,第二个图像是在单击undobutton之后

单击撤消按钮之前 单击撤消按钮后

问候Ranjit

Mar*_*nny 5

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

您应该能够UIGraphicsBeginImageContextWithOptions使用scaleset 调用0.0.来自文档:

要应用于位图的比例因子.如果指定值0.0,则比例因子将设置为设备主屏幕的比例因子.