当前位置:去问问>生活百科>c# 保存picturebox图片

c# 保存picturebox图片

2024-09-14 10:41:04 编辑:zane 浏览量:573

c# 保存picturebox图片

的有关信息介绍如下:

c# 保存picturebox图片

你要想保存pictureBox1上的图片必须在pictureBox1的paint事件里绘制,然后再调用pictureBox1的DrawToBitmap方法保存在图片里,最后在把图片保存到硬盘上,不过这样太麻烦不如直接绘制在图片上,代码如下两种方法都有 //在pictureBox1的Paint事件里绘制 private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawString("Hello World", this.Font, Brushes.Black, new PointF(10, 10)); } private void button1_Click(object sender, EventArgs e) { Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height); pictureBox1.DrawToBitmap(bit, pictureBox1.ClientRectangle); bit.Save("C:\\Picture1.bmp", System.Drawing.Imaging.ImageFormat.Bmp); bit.Dispose(); } //直接绘制在Bitmap上并保存 private void button2_Click(object sender, EventArgs e) { Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(bit); g.Clear(Color.White); g.DrawString("Hello World", this.Font, Brushes.Black, new PointF(10, 10)); g.Dispose(); bit.Save("C:\\Picture2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); bit.Dispose(); }

版权声明:文章由 去问问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.qwenw.com/life/378851.html
热门文章