使用ACEDrawingView绘制问题

时间:2013-12-31 10:43:35

标签: ios iphone cocos2d-iphone

我想使用ACEDrawing实现快进功能。我正在做的是当用户绘制任何绘图时,我记录了用于绘制线条的所有点。因此,在用户完成绘图后,我将获得使用绘制线的所有点。所以我想开发快进功能,用户可以点击一个按钮查看最终的绘图。我已经实现了如下所示的代码。它适用于小型绘图,例如2000点。但当点数增加到1000000以上时就崩溃了。我不知道它是如何处理的。任何好友都能对此提出建议吗?

代码:

    self.currentTool = ACEDrawingToolTypePen;
    self.currentTool.lineWidth = self.lineWidth;
    self.currentTool.lineColor = [UIColor blackColor];
    self.currentTool.lineAlpha = 1;
    [self.currentTool setInitialPoint:currentPoint];
    [self.pathArray addObject:self.currentTool];
    currentPointArray = [mainDictionary objectForKey:@"points"];
    for (int j = 2; j<[currentPointArray count]; j++) {

         currentPoint = CGPointMake([[[currentPointArray objectAtIndex:j] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:j] objectForKey:@"y"] floatValue]*heiMul);

         previousPoint2 = CGPointMake([[[currentPointArray objectAtIndex:j-2] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:j-2] objectForKey:@"y"] floatValue]*heiMul);
         previousPoint1 = CGPointMake([[[currentPointArray objectAtIndex:j-1] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:j-1] objectForKey:@"y"] floatValue]*heiMul);
         if ([self.currentTool isKindOfClass:[ACEDrawingPenTool class]]) {

              CGRect bounds = [(ACEDrawingPenTool*)self.currentTool addPathPreviousPreviousPoint:previousPoint2 withPreviousPoint:previousPoint1 withCurrentPoint:currentPoint];
              CGRect drawBox = bounds;
              drawBox.origin.x -= self.lineWidth * 1.0;
              drawBox.size.width += self.lineWidth * 2.0;
              drawBox.size.height += self.lineWidth * 2.0;
              [self setNeedsDisplayInRect:drawBox];
        }
        [self updateCacheImage:NO];
}

1 个答案:

答案 0 :(得分:0)

好像你有记忆问题。

您可以按如下方式更改代码。 在updateCacheImage方法中,您需要将imageContext放入AutoReleaspool以释放记忆。

@autoreleasepool {

    // init a context
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

    //End Context
    UIGraphicsEndImageContext();
}

您还必须将对象设置为nil以释放内存,如下所示:

id object;
object = nil;
相关问题