SORU
22 ŞUBAT 2011, Salı


iPhone düzgün çizim algoritması

İPhone çizimi bir uygulama üzerinde çalışıyorum. Burada görüldüğü gibi çalışıyor fakat çok var enter image description here

Ve herhangi bir öneri için çizim yumuşatmak için arıyorum Yaptığım şey temel olarak, kullanıcı aradım ekranda bir parmak yerleştirir

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

sonra bir diziye tek bir dokunuş topluyorum

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

ve kullanıcı ekranından bir parmak sol, aradım

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

o zaman dizideki tüm noktaları kullanarak çiziyorum

NSMutableArray *points = [collectedArray points];   

CGPoint firstPoint;
[[points objectAtIndex:0] getValue:&firstPoint];

CGContextMoveToPoint(context, firstPoint.x, firstPoint.y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);

for (int i=1; i < [points count]; i  ) {
    NSValue *value = [points objectAtIndex:i];
    CGPoint point;
    [value getValue:&point];    
    CGContextAddLineToPoint(context, point.x, point.y);

} 

CGContextStrokePath(context);
UIGraphicsPushContext(context);

Ve şimdi "" Uygulama Eskiz Defteri gibi çizim tobe geliştirmek istiyorum enter image description here

Sinyal işleme algoritması ile dizideki tüm noktaları yeniden düzenlemek için bir şey yok sanırım ama emin değilim. Herhangi bir Yardım çok mutluluk duyacağız.

Önceden:) Thankz

CEVAP
31 Mart 2011, PERŞEMBE


CGPoint midPoint(CGPoint p1, CGPoint p2)
{

    return CGPointMake((p1.x   p2.x) * 0.5, (p1.y   p2.y) * 0.5);

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];

    previousPoint1 = [touch previousLocationInView:self];
    previousPoint2 = [touch previousLocationInView:self];
    currentPoint = [touch locationInView:self];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];

    previousPoint2 = previousPoint1;
    previousPoint1 = [touch previousLocationInView:self];
    currentPoint = [touch locationInView:self];


    // calculate mid point
    CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
    CGPoint mid2 = midPoint(currentPoint, previousPoint1);

    UIGraphicsBeginImageContext(self.imageView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.imageView.image drawInRect:CGRectMake(0, 0, self.imageView.frame.size.width, self.imageView.frame.size.height)];

    CGContextMoveToPoint(context, mid1.x, mid1.y);
    // Use QuadCurve is the key
    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 

    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, 2.0);
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
    CGContextStrokePath(context);

    self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Google Analytics

    Google Analy

    25 ŞUBAT 2008
  • ItZWaffleS420

    ItZWaffleS42

    9 EYLÜL 2011
  • Top Gear

    Top Gear

    27 Mart 2006