Update a drawing without deleting the previous one

前端 未结 2 664
鱼传尺愫
鱼传尺愫 2020-11-27 08:41

I created this within a drawing method

private void draws()
{
 Bitmap bmp = new Bitmap(pictureBox17.Width, pictureBox17.Height);
 using (Graphics g = Graphic         


        
2条回答
  •  隐瞒了意图╮
    2020-11-27 08:58

    Try creating the Bitmap outside of the function to preserve it, the way you are doing it now disposes of the Bitmap element after the function has completed.

    you could then do something like

    Bitmap bmp = new Bitmap(pictureBox17.Width, pictureBox17.Height);
        private void draws()
        {
         if (bmp ==null)
         using (Graphics g = Graphics.FromImage(bmp))
                    {
                        //define area do pictureBox17 e preenche a branco
                        Brush brush = new SolidBrush(Color.White);
                        Rectangle area = new Rectangle(0, 0, pictureBox17.Width, pictureBox17.Height);
                        g.FillRectangle(brush, area);
                        //desenha as linhas do rectangulo
                        g.DrawLine(new Pen(Color.Black), esp, esp, esp, yWcorrigidoesp);
                     }
       else {
             using (Graphics g = Graphics.FromImage(bmp))
             {
                g.DrawLine(new Pen(Color.Black), esp, esp, esp, yWcorrigidoesp);
             }
        // some more lines
        }
         pictureBox17.Image = bmp;
        }
    

    Just to get you started.. :)

    Alternatively you can pass the bmp into the draw function if you use this method to draw multiple bmp at different times

提交回复
热议问题