Dinesh
Dinesh

Reputation: 6532

How to Save and Load Drawing lines iphone SDK

I want to Save Drawing lines permanently and load Drawing lines saved from Project resource...!

Now i am get x and y position on touch move event.i want to save the x and y position in local resource on a project,But i am not experience in ios for no idea...!

And Load Saved x and y position from project local resource saved file..!

I want to Save Drawing lines Below like this:

enter image description here

Please any one Help me with Greatly appreciated...!

Thanks...!

Upvotes: 5

Views: 1167

Answers (2)

iBhavik
iBhavik

Reputation: 647

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

    if(!mouseSwiped) {
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
        UIGraphicsBeginImageContext(ivBack.frame.size);
        [drawImage.image drawInRect:CGRectMake(0,0, self.ivBack.frame.size.width,self.ivBack.frame.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line);
        CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [pickColor CGColor]);
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        CGContextFlush(UIGraphicsGetCurrentContext());

 NSData *dataImage=UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
        [dataImage writeToFile:[self SavedImage:(@"1.png")] atomically:YES];
        drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
}

that will defenatly solve ur question

Upvotes: 3

keegan3d
keegan3d

Reputation: 11285

If you want to store the x and y positions you could store up an array then save that to disk with writeToFile. This will write the data to disk in plist format.

NSMutableArray *points = ...
[points writeToFile:someFileInTheBundle atomically:YES];

You could also store the drawing as an image and write that to disk. This category I wrote should help with this by giving you an image for your drawing code: https://github.com/kgn/BBlock/blob/master/UIImage%2BBBlock.m

Upvotes: 2

Related Questions