C#,GDI+ 保存图像

获取一个picturebox控件的graphics对象后,在上面画图,画好后,如果想把图像保存成图片,应该怎么保存呢?privatevoidbtnRandom_Click... 获取一个picturebox控件的graphics对象后,在上面画图,画好后,如果想把图像保存成图片,应该怎么保存呢?

private void btnRandom_Click(object sender, EventArgs e)
{
this.pictureBox1.Refresh();
this.ShowData();
this.timer1.Start();
timer1.Tick += new EventHandler(timer1_Tick);
}

void timer1_Tick(object sender, EventArgs e)
{
this.pictureBox1.Refresh();
this.ShowData();
}

private void btnAdd_Click(object sender, EventArgs e)
{
this.timer1.Stop();
this.ShowData();
}

private void ShowData()
{
Graphics g = this.pictureBox1.CreateGraphics();
TestCreatePoint createPoint = new TestCreatePoint(16, "time");
GDIShowData showData = new GDIShowData();
GDIDrawCoordinate showCoordinate = new GDIDrawCoordinate(new Point(30, this.pictureBox1.Height - 30), new Point(this.pictureBox1.Width - 10, 10), 20, 20);
ArrayList randomList = createPoint.Randtimeseries(30, 100, this.pictureBox1.Height - 100);
showData.DrawPoint(g, randomList);
showData.DrawLine(new Pen(Color.Black, 1), g, randomList);
showCoordinate.GDIDrawAxis(g, new Pen(Color.Brown, 3));
showCoordinate.GDIDrawGrid(g, new Pen(Color.Gray, 1));
showCoordinate.GDIDrawXYDirection(g, 0, -100, 10, 200 / showCoordinate.yCount, "Time-Series/Unit:Day","Defor/Unit:mm");
Pen pen = new Pen(Color .Orange ,2);
pen.DashStyle = DashStyle.Dot;
showCoordinate.GDIDrawWarningLine(g,pen,135);
showCoordinate.GDIDrawLineDirection(g,new Point (showCoordinate .endPoint .X -150,showCoordinate .endPoint .Y +20));
randomList.Clear();

g.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
this.pictureBox1.Image.Save(@"C:\My Documents\Visual Studio 2008\GDITest\GDIControl\Images\SavedImages\FullImage.jpg");
}

运行的时候在save时间处理函数里面,提示错误:
未将对象引用设置到对象的实例。
展开
 我来答
foolishai
2009-12-04 · TA获得超过155个赞
知道小有建树答主
回答量:161
采纳率:0%
帮助的人:146万
展开全部
不可以那样保存...用GDI绘制后的图不是画到this.pictureBox1.Image里面,因为image是空的,所以出现这个错误
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式