Smooth-Line-View icon indicating copy to clipboard operation
Smooth-Line-View copied to clipboard

Changing colour/width affects previous paths

Open jameshoward opened this issue 13 years ago • 5 comments

This is a really great project and performs very well even on Retina iPad displays.

If you change the lineColor or lineWidth property and then attempt to draw another line, any previous paths that fall within the rectangle drawn in drawRect are updated to the new colour/width.

This makes sense since all drawn paths are added to the single mutable path but it's not ideal. I've been wondering about saving existing paths in onTouchesEnded but I'm not sure what is best to save to - UIImage, a sub-view or maybe a CGLayer.

jameshoward avatar Sep 24 '12 10:09 jameshoward

I have tried experimenting with storing path/colour/width for all paths in an array and adding them all to the context in drawRect. Each touchesEnded pushes the current path onto the stack and starts a new path ready for the next drawing.

This works fine for being able to have lots of lines of different widths and colours. It slows slightly when there are loads of paths as you'd expect so maybe rasterizing is still the answer. This would also allow basic eraser functionality by using the clear blend mode on that combined image.

I wonder if having a UIImageView subview (or indeed extending UIImageView) and writing down to that in drawInRect might be a solution. I guess the issue is that each drawInRect call would need to write on top of the current image, most likely meaning it needs to be drawn into the context repeatedly, causing performance issues.

jameshoward avatar Sep 25 '12 11:09 jameshoward

I did it with a mutable array of paths, it doesn't seem to slow things down that bad. I'll try to put it up on github

andsmi avatar Nov 13 '12 13:11 andsmi

I look forward to the updated code on github.

narmontas avatar Nov 15 '12 09:11 narmontas

@andsmi , could you please put your code changes to github

lanbozhang avatar Apr 11 '13 02:04 lanbozhang

@andsmi Could you share your code for the mutable array of paths please?

ghost avatar Jul 17 '16 16:07 ghost