中企動(dòng)力免費(fèi)做網(wǎng)站實(shí)時(shí)熱搜
在winform開發(fā)中,有時(shí)會(huì)用到截圖并保存為圖片的時(shí)候,這里列了三種保存圖片的可能情況。
將窗體截圖保存成圖片的方式是:
Bitmap bit = new Bitmap(this.Width, this.Height);//實(shí)例化一個(gè)和窗體一樣大的bitmap
Graphics g = Graphics.FromImage(bit);
g.CompositingQuality = CompositingQuality.HighQuality;//質(zhì)量設(shè)為最高
g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整個(gè)窗體為圖片
//g.CopyFromScreen(pbx.PointToScreen(Point.Empty), Point.Empty, pbx.Size);//只保存某個(gè)控件(這里是pbx是圖片控件)
bit.Save("weiboTemp.png");//默認(rèn)保存格式為PNG,保存成jpg格式質(zhì)量不是很好
將控件截圖保存成圖片:
//保存dataGridView1截圖
Bitmap newbitmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);
dataGridView1.DrawToBitmap(newbitmap, new Rectangle(0, 0, newbitmap.Width, newbitmap.Height));
newbitmap.Save("test.gif");
將背景圖片保存為圖片則非常簡單:
Image picture = this.BackgroundImage;//將背景圖片賦給picture
picture.Save("back.png");
原文鏈接:【C#】截圖并保存為圖片_c#保存截圖-CSDN博客