高分,请问在C#中如何把线保存为一个文件 如题,怎么在C#中如何把线保存为一个文件,只保存一段画的线 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 b.Save("e:\\00.jpg",ImageFormat .Jpeg); 先用GDI画线,再保存为文件http://www.cnblogs.com/xuasmi/archive/2008/09/19/1294255.html 试试用对象数据库来解决:http://download.csdn.net/user/dz_huanbao namespace C版本轨迹线{ public partial class Form1 : Form { int x=0; int y=0; Pen myPen = new Pen(Color.Red); public Graphics g; public Boolean ifFirst=false ; Point pPoint1 = new Point(); Point pPoint2 = new Point(); Point TempPoint = new Point(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { g = this.CreateGraphics(); myPen.Width = 5; g.DrawLine(myPen, 10, 10, 100, 100); } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (pPoint1 == null) { pPoint1 = new Point(); pPoint1.X = e.X ; // .PutCoords(e.mapX, e.mapY); pPoint1.Y = e.Y; } else { pPoint1.X = TempPoint.X; pPoint1.Y = TempPoint.Y; } if (pPoint2 == null) { pPoint2 = new Point(); pPoint2.X = pPoint1.X; pPoint2.Y = pPoint1.Y; } else { pPoint2.X = e.X ; // .PutCoords(e.mapX, e.mapY); pPoint2.Y = e.Y; } g = this.CreateGraphics(); myPen.Width = 5; g.DrawLine(myPen, pPoint1 .X , pPoint1 .Y , pPoint2 .X , pPoint2 .Y ); TempPoint = new Point(); TempPoint.X = pPoint2.X; TempPoint.Y = pPoint2.Y; } }}以上是我点击鼠标画线的代码,我想把画的线保存为一个文件,只保存线为一个文件,请大侠们贴出具体的代码呀 public partial class Form1 : Form { List<Point> points = new List<Point>(); // 用于保存点击轨迹 Pen myPen = new Pen(Color.Red, 5); public Form1() { InitializeComponent(); points.Add(Point.Empty); this.DoubleBuffered = true; // 启用DoubleBuffer以减少闪烁 } protected override void OnPaint(PaintEventArgs e) // <--画轨迹的地方,也就是重画窗体的地方 { if (points.Count > 1) { e.Graphics.DrawLines(this.myPen, this.points.ToArray()); } } private void Form1_MouseDown(object sender, MouseEventArgs e) { points.Add(e.Location); // 添加鼠标点击的点 this.Invalidate(); // 并要求重画所有轨迹 } private void button1_Click(object sender, EventArgs e) // 保存或装入(用xml的方式) { bool saving = !this.button1.Text.Contains("Load"); this.button1.Text = saving ? "Load" : "Save"; XmlSerializer serialier = new XmlSerializer(typeof(List<Point>)); // 简洁起见,这里没有检查文件是否存在等等 using (FileStream fs = new FileStream("mylines.xml", FileMode.OpenOrCreate)) { if (saving) { serialier.Serialize(fs, this.points); this.points.Clear(); } else { this.points = serialier.Deserialize(fs) as List<Point>; } } this.Invalidate(); } } 做一个画线的Class,然后系列化保存 1、保存点的轨迹成point[],序列化到文件。还原时读出来再画。2、存图片,下次直接取出来,加到一个新的Bitmap上,可以透明合并到其他图片上,作为一个图元。如果lz做一个画图工具的话,两种都可以。 save the following information into a filestartPoint [x,y,sequenceNo]point[x,y, sequenceNo].....endPoint[x,y,sequenceNo]you will be able to redrew the line by reading the content of the file. 楼上的各位兄弟,那我要保存为什么格式的文件呢,我想保存为线类型的文件(.gen)格式的文件可以吗,请你们在我写的代码那儿加个命令按钮为保存的,然后直接写保存的代码行吗,因为单击画线的代码我已经写好了,你们写保存的代码,谢了 在IIS 6.0中httpmodules无法接管html请求,请问怎么回事? BackGroundWorker 组件 内存释放问题 【难】 VS 2010 RDLC报表 请教高手,这样的效果如何能否实现? 初学c#向sql 添加数据 怎么都不成功 望高人指点 初级问题,函数声明上中括号里的内容代表什么。。 c#在Winform中怎么获取DataGrid当前选定行对应的数据(50分求解) 已定义了一个名为“this”的具有相同参数类型的成员错误 axWebBrowser如何调用应用程序的方法呢 如何实现虚拟框架(不用其他工具或者飞信) 如何在跳转页面的时候清理缓存
http://www.cnblogs.com/xuasmi/archive/2008/09/19/1294255.html
{
public partial class Form1 : Form
{
int x=0;
int y=0;
Pen myPen = new Pen(Color.Red);
public Graphics g;
public Boolean ifFirst=false ;
Point pPoint1 = new Point();
Point pPoint2 = new Point();
Point TempPoint = new Point();
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
g = this.CreateGraphics();
myPen.Width = 5;
g.DrawLine(myPen, 10, 10, 100, 100);
} private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (pPoint1 == null)
{
pPoint1 = new Point();
pPoint1.X = e.X ; // .PutCoords(e.mapX, e.mapY);
pPoint1.Y = e.Y;
}
else
{
pPoint1.X = TempPoint.X;
pPoint1.Y = TempPoint.Y;
} if (pPoint2 == null)
{
pPoint2 = new Point();
pPoint2.X = pPoint1.X;
pPoint2.Y = pPoint1.Y;
}
else
{
pPoint2.X = e.X ; // .PutCoords(e.mapX, e.mapY);
pPoint2.Y = e.Y; } g = this.CreateGraphics();
myPen.Width = 5;
g.DrawLine(myPen, pPoint1 .X , pPoint1 .Y , pPoint2 .X , pPoint2 .Y );
TempPoint = new Point();
TempPoint.X = pPoint2.X;
TempPoint.Y = pPoint2.Y;
}
}
}以上是我点击鼠标画线的代码,我想把画的线保存为一个文件,只保存线为一个文件,请大侠们贴出具体的代码呀
public partial class Form1 : Form
{
List<Point> points = new List<Point>(); // 用于保存点击轨迹
Pen myPen = new Pen(Color.Red, 5); public Form1()
{
InitializeComponent();
points.Add(Point.Empty);
this.DoubleBuffered = true; // 启用DoubleBuffer以减少闪烁
} protected override void OnPaint(PaintEventArgs e) // <--画轨迹的地方,也就是重画窗体的地方
{
if (points.Count > 1)
{
e.Graphics.DrawLines(this.myPen, this.points.ToArray());
}
} private void Form1_MouseDown(object sender, MouseEventArgs e)
{
points.Add(e.Location); // 添加鼠标点击的点
this.Invalidate(); // 并要求重画所有轨迹
} private void button1_Click(object sender, EventArgs e) // 保存或装入(用xml的方式)
{
bool saving = !this.button1.Text.Contains("Load");
this.button1.Text = saving ? "Load" : "Save";
XmlSerializer serialier = new XmlSerializer(typeof(List<Point>)); // 简洁起见,这里没有检查文件是否存在等等
using (FileStream fs = new FileStream("mylines.xml", FileMode.OpenOrCreate))
{
if (saving)
{
serialier.Serialize(fs, this.points);
this.points.Clear();
}
else
{
this.points = serialier.Deserialize(fs) as List<Point>;
}
}
this.Invalidate();
}
}
2、存图片,下次直接取出来,加到一个新的Bitmap上,可以透明合并到其他图片上,作为一个图元。
如果lz做一个画图工具的话,两种都可以。
save the following information into a filestartPoint [x,y,sequenceNo]
point[x,y, sequenceNo]
.....
endPoint[x,y,sequenceNo]you will be able to redrew the line by reading the content of the file.