如何取得绘制控件的图片并保存

dai78 2008-07-16 05:31:25
我用pictureBox控件,并在此控件上用代码绘制图,绘制完后,如何取该图并保存
private void PicIn_Paint(object sender, PaintEventArgs e)
{
//在pictureBox上绘制图
e.Graphics.DrawLine(black35KvPen, 10, 0, 10, 50);
e.Graphics.DrawLine(black35KvPen, 10, 35, 60, 35);
e.Graphics.DrawLine(black35KvPen, 60, 35, 60, 50);
e.Graphics.DrawLine(black35KvPen, 10, 0, 7, 25);
e.Graphics.DrawLine(black35KvPen, 10, 0, 13, 25);


}
...全文
127 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
baihe_591 2008-07-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 djc7811 的回复:]
谢谢7楼的指正,如果采用你所说的方法,当控件大小变化时如何更改Image在控件上显示的大小?谢谢
[/Quote]

那你将控件该为picturebox,
picturebox.image=bimp;
picturebox.sizemode=autosize;
dai78 2008-07-18
  • 打赏
  • 举报
回复
谢谢7楼的指正,如果采用你所说的方法,当控件大小变化时如何更改Image在控件上显示的大小?谢谢
卧_槽 2008-07-18
  • 打赏
  • 举报
回复
你的方法比较愚昧。
应该先画在一个image对象上,然后把image对象画到控件上。
因为控件是用户界面层,没有存储和修改数据的设计。
加上image对象以后,可以构建数据层。
dai78 2008-07-18
  • 打赏
  • 举报
回复
我这是先绘制到控件上,然后在另外一个地方取控件上的图,并保存。而上述的都是先建立Bitmap并指定到Bitmap然后再画图保存
s000rd 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hongqi162 的回复:]
C# codeGraphics g;
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//创建一张200*200的图片 你可以修改成别的
g = Graphics.FromImage(bitmap);//指定bitmap
g.DrawLine(....);
bitmap.Save("yourfilename");
[/Quote]
hongqi162 2008-07-16
  • 打赏
  • 举报
回复
Graphics g;
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);//创建一张200*200的图片 你可以修改成别的
g = Graphics.FromImage(bitmap);//指定bitmap
g.DrawLine(....);
bitmap.Save("yourfilename");
hongqi162 2008-07-16
  • 打赏
  • 举报
回复
this.pictureBox1.Image.Save("yourfilename");
grearo 2008-07-16
  • 打赏
  • 举报
回复
Image img = PictureBox1.Image;
img.Save(@filepath);
kkun_3yue3 2008-07-16
  • 打赏
  • 举报
回复
你新建一个Bitmap,在这上面画,画完了Save下!

111,048

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧