在Picturebox上绘制图像并保存

时间:2013-09-24 18:15:45

标签: c# picturebox

我正在开发一个程序来获取高级截图。但我遇到了一个错误,我希望有人可以帮助我。

  • 我可以使用以下代码制作屏幕截图:

           // The screenshot will be stored in this bitmap.
        Bitmap capture = new Bitmap(screenBounds.Width, screenBounds.Height);
    
        // The code below takes the screenshot and
        // saves it in "capture" bitmap.
        g = Graphics.FromImage(capture);
        g.CopyFromScreen(Point.Empty, Point.Empty, screenBounds);
    
        // This code assigns the screenshot
        // to the Picturebox so that we can view it
        pictureBox1.Image = capture;
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    
        // The code below make the form visible again, enables the "Save" button and stops the timer.
        this.Show();
        button2.Enabled = true;
        timer1.Stop();
    
  • 在图片框上绘图:

            color = new SolidBrush(Color.Black);
            Graphics g = pictureBox1.CreateGraphics();
            g.FillEllipse(color, e.X, e.Y, 10, 10);
            g.Dispose();
    

问题:我只能保存截图,而不是图纸。
我希望有人可以帮助

1 个答案:

答案 0 :(得分:0)

不要使用CreateGraphics() - 这是一张临时图纸。使用您的捕获图像:

using (Graphics g = Graphics.FromImage(capture)) {
  g.FillEllipse(color, e.X, e.Y, 10, 10);
}