1

I have to develop a painting application in C# using the mouse movement, so I decided to use a List of GraphicsPath where I store the path for each drawing (consider the drawing as the path painted between a mouseDown and mouseUp event). Each path is composed of lines between the previous and current mouse positions.

At the same time, overriding the OnPaint event allows me to display those paths with a good refreshing rate. The problem arises in a specific scenario where the user takes a pen color with some transparency and draws the path over an existing one, resulting in color overlapping..:

enter image description here

This situation breaks one of the requirements of the project because there cannot be any color mix. The last drawn color has to be preserved. I tried to use Regions and the Exclude method, but the results are not the desired ones because regions do not fit accurately the path of the line, and the execution time increases drastically.

I've been working on it for weeks and I haven't been able to reach any good solution for this problem.

Any suggestions?

TaW
  • 53,122
  • 8
  • 69
  • 111
MarioAF
  • 23
  • 4
  • 2
    Why allow semi-transparency when you don't want it? – TaW Jan 19 '21 at 17:01
  • Yeah sorry, maybe it was not very clear. That situation can happen because one of the applications of the program has to be image segmentation. For instance, if the user wants to segment an image with some pedestrians, it's convenient to allow the use of non-opaque colors to know the pixels that you're segmenting. – MarioAF Jan 19 '21 at 18:11
  • Hm, I see. Depending on the full range of things to do one may consider this: You could introduce layers, a new one whenever a new color is picked. What about when the path crosses a path with the same color? – TaW Jan 19 '21 at 18:19
  • The more I think about it, the more I believe that a solution with layered levels could do what you need. It needs a new canvas (I suggest a Label subclass) for each color, which you nest in the control you use now. When you need to you can always switch each layer off. All layers must be nested in the one below it. To hide a layer simply set a flag that controls if it shall draw its content.. I did this a few years ago and it worked really well, even with a miniature preview for each layer ;-) – TaW Jan 19 '21 at 19:10
  • It is an approach that I have not explored, so I will definitely work on it because it seems very promising. Thank you very much! I really appreciate the time you have expended figuring out a possible solution. – MarioAF Jan 19 '21 at 20:18

0 Answers0