Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello community:

I'm working on an image editor (it's really like a hobby) and I'm having a little problem with te visual representation of the image and changes.
The project follows the MVC dessign pattern, (the project is in fact a little more complicated that a simple image editor but this is not what matters) and for the editing I use a board ("pixel's" matrix) as the model part and a modified view panel (its responsability is to make the visual representation of the state of the board)

When I modified the board (for example, painting one pixel with a pen) I invalidate the panel and it has to fully repaint itself. (I supposse given the fact that a PC automatics refresh (repaint) itself several times per seconds the CPU will not mind to repaint the entire panel each time I modify just one pixel)
The problem is that the image blinks, and if I move my "pen fast", you don't see a line, you see a dashed line.
The complexity of my "repainting" algorithm is O(n^2).

Anyone can suggest me a better algorithm or a better dessign pattern that I can use in order to fix this problem...

Thanx for reading and please excuse my bad english...
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-12 1:14am    
What is the UI library? (Please don't answer "MVC", which can be understood in different sense, tell if it is Forms, WPF, ASP.NET, Silverlight, Metro, etc.)

Very basically: you might observe flicker, which can be reduced using double buffering. Do you understand how it works?
--SA
Sergey Alexandrovich Kryukov 2-Dec-12 1:21am    
By the way, let me tell you the truth: your English looks good enough and it's much, much better then average for a typical forum enquirers.

--SA
mdarefull 2-Dec-12 1:39am    
I used different styles like Double Buffering & Opaque.
The UI is windows.Forms, MVC means Model-View-Controller what is a dessign pattern.

I think the problem is the method that I use to manipulate the image. Each time a pixel is changed I invalidate the panel, so it has to totally repaint itself.
If I draw a single line of, in example 100 pixels, in a second, that means that for an 1024x768 image the panel (try to) paint 786432 pixels 100 times. What I think is much more that what my CPU can handle.
The problem is that I don't have idea of do this in other way...
Peter_in_2780 2-Dec-12 2:09am    
Two things. I think the system buffers "invalidate" events, so the numbers might not be as bad as you think. The other thing is to just invalidate less often, for example only when you have finished drawing a line, or a polygon or whatever. Just don't do it every pixel.
Sergey Alexandrovich Kryukov 2-Dec-12 13:51pm    
Right, the invalidation should be once per "frame", otherwise the system behaves like you really need to see all those intermediate transitions; in other word, you show the system that the flicker is legitimate. :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900