diff --git a/ACEDrawingView/ACEDrawingView.h b/ACEDrawingView/ACEDrawingView.h index 138274b..f2af6cf 100644 --- a/ACEDrawingView/ACEDrawingView.h +++ b/ACEDrawingView/ACEDrawingView.h @@ -91,6 +91,10 @@ typedef NS_ENUM(NSUInteger, ACEDrawingMode) { - (BOOL)canRedo; - (void)redoLatestStep; +// Save & load drawing +- (void)loadDrawing:(NSMutableArray *)pathArray; +- (NSMutableArray *) getPathArray; + /** @discussion Discards the tool stack and renders them to prev_image, making the current state the 'start' state. (Can be called before resize to make content more predictable) diff --git a/ACEDrawingView/ACEDrawingView.m b/ACEDrawingView/ACEDrawingView.m index de3eaf7..adfe66c 100644 --- a/ACEDrawingView/ACEDrawingView.m +++ b/ACEDrawingView/ACEDrawingView.m @@ -488,6 +488,43 @@ - (void)hideTextToolHandles } } +- (NSMutableArray *) getPathArray { + return _pathArray; +} + +- (void)loadDrawing:(NSMutableArray *)pathArray { + + _pathArray = pathArray; + + // init a context + UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); + + + // erase the previous image + self.image = nil; + + // load previous image (if returning to screen) + + switch (self.drawMode) { + case ACEDrawingModeOriginalSize: + [[self.backgroundImage copy] drawAtPoint:CGPointZero]; + break; + case ACEDrawingModeScale: + [[self.backgroundImage copy] drawInRect:self.bounds]; + break; + } + + // I need to redraw all the lines + for (id tool in self.pathArray) { + [tool draw]; + } + + // store the image + self.image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); +} + + #pragma mark - Undo / Redo - (BOOL)canUndo