日期:2014-05-18  浏览次数:20984 次

如何保存winfrom上的内容
Point p;
private void Form2_MouseDown(object sender, MouseEventArgs e)
{

  p = e.Location;

private void Form2_MouseMove(object sender, MouseEventArgs e)
{
  Graphics g = this.CreateGraphics();
  Pen myPen = new Pen(Color.Black);
  g.DrawLine(myPen, p, e.Location);
  p = e.Location;
   
}
以上代码可以在窗体上画出鼠标轨迹
问题是:如何将窗体上画的鼠标轨迹保存成图像文件存在硬盘上?


------解决方案--------------------
可以把轨迹中的点储存下来,在保存到文件时根据这些点再重画出来。

ArrayList<Point> points = new ArrayList<Point>();
Point p;
private void Form2_MouseDown(object sender, MouseEventArgs e)
{
p = e.Location;
points.Add(p);


private void Form2_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen myPen = new Pen(Color.Black);
g.DrawLine(myPen, p, e.Location);
p = e.Location;
points.Add(p);

}
------解决方案--------------------
1. 换用别的存储方法. 比如说int类型的数组
2. 降低采样的频率以节省空间
------解决方案--------------------
no way to solute the problem. Only up 2.
------解决方案--------------------
顶,似乎有更好的方法
------解决方案--------------------
把ArrayList改成List就可以了