Kikx

Kikx

  • NA
  • 9
  • 12.1k

Smoother drawing pen

Sep 7 2012 10:27 PM
Hello

I have a paint application made in C#/GDI+ (winform), capable of drawing shapes with changeable pen size and color. I have a method for a 'free pen' as you would normally find in MS Paint, but it is quite ugly.
The app works that firstly, a graphics object is created from a pre-defined bitmap. Then, the user draws images on to the bitmap which are then showed on the panel using the panel paint event. I am guessing that the 'ugliness' is due to the time it takes to go through all those steps. Is there another way to make this smoother? See pic and code for detail

if (crtanje)
                {
                    debljina = float.Parse(debljina_box.Text);
                    Graphics gr = Graphics.FromImage(bit);
                    gr.SmoothingMode = SmoothingMode.HighQuality;
                    olovka = new Pen(boja, debljina);
                    gr.DrawLine(olovka, new Point(prethodnoX ?? e.X, prethodnoY ?? e.Y), new Point(e.X, e.Y));
                    panel1.CreateGraphics().DrawImageUnscaled(bit, new Point(0, 0));
                    prethodnoX = e.X;
                    prethodnoY = e.Y;
                }



Answers (2)