Save the drawing and open it again
many thanks for this great sample project. I want to ask if you can give me a tip. I want to save the drawn lines, shapes, etc.. I do not mean save as png or pdf. Rather, I want to save the contents of the "self.pathArray" and load this data later in the "drawingView". Later the drawing is to be further processed. If there still remain the UnDo steps, it would be perfect.
I try and try ... but do not get ahead. it would be great if you could help me. sincerely thomas.
We would need to have all the drawing tools adhere to the NSCoding protocol. UIBezierPath already supports it, but we also need to (de)code the colors, line size, etc.
If someone feels like sending a pull-request, that would be useful.
Just adding how I did this, incase some one is in need.
- Make the following code public in ACEDrawingView.h
@property (nonatomic, strong) NSMutableArray *pathArray;
@property (nonatomic, strong) NSMutableArray *bufferArray;
- (void)updateCacheImage:(BOOL)redraw;
- Save pathArray and bufferArray from the previous instance of ACEDrawingView.
- When a new ACEDrawingView (let it be 'drawView') is created provide it with the values from previously saved pathArray and bufferArray.
- Over ride layoutSubviews() in parent view and call the method drawView.updateCacheImage(True)
Note: drawView.updateCacheImage(True) will work only when its called before the view is displayed. I found that calling this method after view is loaded, some how makes the drawings hidden and appears when we draw over it again.
Disclaimer: Not tested properly. Will add the issues after I finish testing.
Hi,vipinjohney I also want to save the drawing and open it again.do you finish testing ? thanks.
Hi vipinjohney
I need to update previous draw lines with selected pattern image.could you help me in this issue. I did what you said above redrawing is working perfectly but those line were not update.
Above solutions by me had many issues. One of them was, each time I redraw the saved lines and draw a new line the previous set of lines changed their location. Tried to fix that but dropped it due to lack of time .