2011-08-06 30 views
9

iOS uygulamasında CoreGraphics kullanarak eğriler çizmeye çalışıyorum. Çizimin kendisi iyi çalışıyor, ancak retina ekranda görüntü aynı çözünürlüğü kullanarak çiziliyor ve piksel ikiye katlanmıyor. Sonuç pikselli bir görüntüdür.CoreGraphics kullanarak retina ekranında çizim - Resim pixelated

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentPoint = [touch locationInView:self.canvasView]; 

    UIGraphicsBeginImageContext(self.canvasView.frame.size); 
    [canvasView.image drawInRect:self.canvasView.frame]; 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGContextSetShouldAntialias(ctx, YES); 
    CGContextSetLineCap(ctx, kCGLineCapRound); 
    CGContextSetLineWidth(ctx, 5.0); 
    CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0); 
    CGContextBeginPath(ctx); 
    CGContextMoveToPoint(ctx, lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(ctx, currentPoint.x, currentPoint.y); 
    CGContextStrokePath(ctx); 
    canvasView.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    lastPoint = currentPoint; 
    // some code omitted from this example 
} 

buldum tavsiye use the scaleFactor property veya CGContextSetShouldAntialias() function oldu, ama bunların hiçbiri bugüne kadar yardım etti:

aşağıdaki işlevleri kullanarak çiziyorum. (Bunları yanlış kullanmış olmama rağmen.)

Herhangi bir yardım büyük memnuniyetle karşılanacaktır.

cevap

27

Sen

if (UIGraphicsBeginImageContextWithOptions != NULL) { 
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); 
} else { 
    UIGraphicsBeginImageContext(size); 
} 

UIGraphicsBeginImageContextWithOptions 4.x yazılımında tanıtıldı ile UIGraphicsBeginImageContext değiştirmeniz gerekiyor. Bu kodu 3.x cihazlarda çalıştırırsanız, UIKit çerçevesinin zayıf linkini kullanmanız gerekir. Dağıtım hedefiniz 4.x veya daha yüksekse, herhangi bir ek kontrol yapmadan UIGraphicsBeginImageContextWithOptions'ı kullanabilirsiniz.

+0

Mükemmel çalışıyor! Teşekkür ederim! – antalkerekes