Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing colour/width affects previous paths #9

Open
jameshoward opened this issue Sep 24, 2012 · 5 comments
Open

Changing colour/width affects previous paths #9

jameshoward opened this issue Sep 24, 2012 · 5 comments

Comments

@jameshoward
Copy link

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
Copy link
Author

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.

@andsmi
Copy link

andsmi commented Nov 13, 2012

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

@narmontas
Copy link

I look forward to the updated code on github.

@lanbozhang
Copy link

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

@ghost
Copy link

ghost commented Jul 17, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants