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时间处理函数里面,提示错误:
未将对象引用设置到对象的实例。 展开
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时间处理函数里面,提示错误:
未将对象引用设置到对象的实例。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询