C# 截屏窗体保存为图片

private void button1_Click(object sender, EventArgs e)
{
Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
Graphics g = Graphics.FromImage(bit);
g.CompositingQuality = CompositingQuality.HighQuality;//质量设为最高
g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
//g.CopyFromScreen(panel游戏区 .PointToScreen(Point.Empty), Point.Empty, panel游戏区.Size);//只保存某个控件(这里是panel游戏区)
bit.Save("D:\\weiboTemp.png");//默认保存格式为PNG,保存成jpg格式质量不是很好

}

转载于:https://www.cnblogs.com/HK0427/p/10304482.html

你可能感兴趣的:(C# 截屏窗体保存为图片)