Fast Forward Drawing using ACEdrawingView

| | August 5, 2015

i am using this :
https://github.com/acerbetti/ACEDrawingView
i want to implemented one Functionality in which i want Fast drawing by clicking on a Button. i am drawing points on screen. i have got success For drawing small amount of points But when i try to draw with more points & draw them with Zero Delay then my app crashes .How can i draw for more points or say more data .!!

-(void)playVideoForDict1:(NSMutableArray*)playvideo widMul:(float)widMul1 heimul:(float)heiMul1 whichValue:(int)thisValue
{

widMul = widMul1;
heiMul = heiMul1;



[NSObject cancelPreviousPerformRequestsWithTarget:self];

for(int i = 0; i<[playvideo count]; i++)
{

    NSDictionary *dict1 = [[NSDictionary alloc] init];
    dict1  = [playvideo objectAtIndex:i];



for(int i=0; i<[playvideo count]; i++)  
{         

    self.currentTool = nil;

    NSDictionary *dict1 = [[NSDictionary alloc] init];
    dict1  = [playvideo objectAtIndex:i];

    if ([dict1 count]==4) 
    {

        self.drawTool = ACEDrawingToolTypePen;            
        self.currentTool = [self toolWithCurrentSettings];
        [self.pathArray addObject:self.currentTool];
        NSDictionary *colorDic = [dict1 objectForKey:@"colore"];
        if ([[dict1 objectForKey:@"lineWidth"] floatValue]==1) {
            self.lineWidth = 5;
        }else if ([[dict1 objectForKey:@"lineWidth"] floatValue]==2) {
            self.lineWidth = 10;
        }else if ([[dict1 objectForKey:@"lineWidth"] floatValue]==3) {
            self.lineWidth = 15;
        }else if ([[dict1 objectForKey:@"lineWidth"] floatValue]==4) {
            self.lineWidth = 30;
        }

        if ([[CCDirector sharedDirector] winSize].width==768)
        {
            self.lineWidth *=2;
        }
        self.currentTool.lineWidth = self.lineWidth;

        self.currentTool.lineColor = [UIColor colorWithRed:[[colorDic objectForKey:@"r"] floatValue] green:[[colorDic objectForKey:@"g"] floatValue] blue:[[colorDic objectForKey:@"b"] floatValue] alpha:1];

        self.currentTool.lineAlpha = 1;

        [self.currentTool setInitialPoint:currentPoint];

        currentPointArray = [dict1 objectForKey:@"points"];

        for (int i = 2; i<[currentPointArray count]; i++) 
        {
            currentPoint = CGPointMake([[[currentPointArray objectAtIndex:i] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:i] objectForKey:@"y"] floatValue]*heiMul);

            previousPoint2 = CGPointMake([[[currentPointArray objectAtIndex:i-2] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:i-2] objectForKey:@"y"] floatValue]*heiMul);
            previousPoint1 = CGPointMake([[[currentPointArray objectAtIndex:i-1] objectForKey:@"x"] floatValue]*widMul, [[[currentPointArray objectAtIndex:i-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.origin.y -= self.lineWidth * 1.0;
                drawBox.size.width += self.lineWidth * 2.0;
                drawBox.size.height += self.lineWidth * 2.0;
                [self setNeedsDisplayInRect:drawBox];
            }
            else 
            {
                [self.currentTool moveFromPoint:previousPoint1 toPoint:currentPoint];
                [self setNeedsDisplay];
            }

        }

         [self updateCacheImage:false];
    }

    else
    {
        NSNumber *check = [dict1 objectForKey:@"undo"];
        if ([check intValue]==1) 
        {
            [self.pathArray removeLastObject];
        }
        else
        {
            [self.pathArray removeAllObjects];
        }
    }
    [self updateCacheImage:true];

}

}

i am stuck with this . please Help on this .. How can i achieve this .

One Response to “Fast Forward Drawing using ACEdrawingView”

  1. it seems i was having memory Issue :

    i Change my code like this :

    In updateCacheImage method :

    You need to put Your imageContext in AutoReleaspool to free up your memory.

    @autoreleasepool {

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

    }

    i also have make my objects To nil for making memory Free like this way :

    id object;
    object = nil;
    

    it works For me.

Leave a Reply