How to save Graphics object as image in C#?

后端 未结 2 1400
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 18:18

I have panel and various controls on it. I would like to save an image of this panel into a file, how can I do this ?

Ineed to do something like screenshot, but I n

2条回答
  •  隐瞒了意图╮
    2020-12-31 18:45

    Use the Control.DrawToBitmap() method. For example:

        private void button1_Click(object sender, EventArgs e) {
            using (var bmp = new Bitmap(panel1.Width, panel1.Height)) {
                panel1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                bmp.Save(@"c:\temp\test.png");
            }
        }
    

提交回复
热议问题