求救:c#中picturebox中用graphics画的图怎么保存成图片出来啊

tjuzm 2010-07-21 03:57:22
c#中picturebox中用graphics画的图怎么保存成图片出来啊
...全文
2663 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kiddc 2010-07-22
  • 打赏
  • 举报
回复
好像pictureBox的paint会在你画完之后又载入原来的那张图,所以好像没画出来。
如果你画图的代码不写在“画图的事件”里面,那么最好把你save的图再度载入pictureBox1,类似这样
this.pictureBox1.ImageLocation = "e:\\XXX.jpg";
this.pictureBox1.Image = Image.FromFile(this.pictureBox1.ImageLocation);
qq2013 2010-07-22
  • 打赏
  • 举报
回复
Bitmap bmp = new Bitmap(pictureBox1.Image,pictureBox1.Width,pictureBox1.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(new Pen(Color.Blue, 10), 100, 100, 0, 0);
bmp.Save("d://1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
wgc 2010-07-22
  • 打赏
  • 举报
回复
        private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image,pictureBox1.Width,pictureBox1.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(new Pen(Color.Blue, 10), 100, 100, 0, 0);
bmp.Save("d://1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
spmzfz 2010-07-22
  • 打赏
  • 举报
回复
参考这个:
pictureBox1.Image = Image.FromFile("pic.jpg");
Graphics G = Graphics.FromImage(pictureBox1.Image);
G.DrawString("Lucky", new Font("楷体", 16F), new SolidBrush(Color.Red), new PointF(0, 0));
pictureBox1.Image.Save("d:\\temp.jpg");
G.Dispose();
LorenLiu 2010-07-21
  • 打赏
  • 举报
回复
额。。这样也行吧。。我个人不太习惯这种写法。。。
tjuzm 2010-07-21
  • 打赏
  • 举报
回复
我知道了,好像是graphics在picturebox上画图不是在picturebox上的图片上画,而是在电脑屏幕上画
private void button3_Click(object sender, EventArgs e)
{
Graphics g;
Pen pen=new Pen(Color.Red,5);
Bitmap bmp = new Bitmap(pictureBox1.Image);
g = Graphics.FromImage((Image)bmp);
g.DrawRectangle(pen, 0, 0, 100,100);
pictureBox1.Image = (Image)bmp;
saveFileDialog1.Title = "save the pictrue";
saveFileDialog1.Filter = "jpg图片(*.jpg)|*.jpg|bmp图片(*.bmp)|*.bmp";
saveFileDialog1.InitialDirectory = "f:\\";

if ((saveFileDialog1.FileName != null) && (saveFileDialog1.ShowDialog()== DialogResult.OK))
{
pictureBox1.Image.Save(saveFileDialog1.FileName);
}
else
{
return;

}

}
LorenLiu 2010-07-21
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 tjuzm 的回复:]
怎么还是不行啊,我把代码发上去你们看看,谢谢
private void button3_Click(object sender, EventArgs e)
{
Graphics g;
g = this.pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Color.Blue, 10), 100, 100, 0, 0);
……
[/Quote]

为什么要用这种方法来画线而不是在paint方法里做呢?
tjuzm 2010-07-21
  • 打赏
  • 举报
回复
怎么还是不行啊,我把代码发上去你们看看,谢谢
private void button3_Click(object sender, EventArgs e)
{
Graphics g;
g = this.pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Color.Blue, 10), 100, 100, 0, 0);
Rectangle m=new Rectangle(0,0,pictureBox1.Width,pictureBox1.Height);
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(bmp, m);

bmp.Save("f://1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
打转的风铃 2010-07-21
  • 打赏
  • 举报
回复
就用我说的那个,肯定没错,呵呵,我就是这么用的!:)
LorenLiu 2010-07-21
  • 打赏
  • 举报
回复
就是把pictureBox的内容都画到一个Bitmap对象上,然后保存Bitmap

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox.Height);
pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save("C:\\1.bmp");
打转的风铃 2010-07-21
  • 打赏
  • 举报
回复
我会,呵呵,做过!!!
 bmp.Save("C:/1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
tjuzm 2010-07-21
  • 打赏
  • 举报
回复
你能说详细点么,我还没明白,我在picturebox中有一张图片,现在我在图片上画个正方形,然后将图片和正方形都一起保存为bmp图片存在磁盘上,谢谢
bdmh 2010-07-21
  • 打赏
  • 举报
回复

Bitmap bmp = new Bitmap(pictureBox1.BackgroundImage);
bmp.Save("c:\\1.bmp");
LorenLiu 2010-07-21
  • 打赏
  • 举报
回复
调用pictureBox的DrawToBitmap方法就可以了

111,083

社区成员

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

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

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