利Graphics g=this.CreateGraphics()进行绘图,保存时只能保存在paint里画的背景图片,并不能保存自己在处理函数里画的线。
而利用Graphics g=Graphics.FormImage();画图时很慢,而且要不断的刷新才能显示画的线。所以这个基本上不想用。
请问谁能帮想一个利用Graphics g=this.CreateGraphics()画线并能保存自己画线的方法?
而利用Graphics g=Graphics.FormImage();画图时很慢,而且要不断的刷新才能显示画的线。所以这个基本上不想用。
请问谁能帮想一个利用Graphics g=this.CreateGraphics()画线并能保存自己画线的方法?
你保存的时候新建一个Bitmap,并且把它的画布传给这个画线的函数。
GraphicsPath mygraphics = new GraphicsPath();
Pen mypen = new Pen(Color.Red, 1); mygraphics.StartFigure();
//为图形路径添加文字
string stringText = this.textBox1.Text;
int style = (int)FontStyle.Italic;
int emSize = 30;//限制字符em(字体大小)方框的高度
//this.panel2.BackgroundImage = mygraphics;
PointF origin = new PointF(0, 0);//设置图形起始位置
StringFormat format = StringFormat.GenericDefault;
mygraphics.AddString(stringText, new FontFamily("Arial"), style, emSize, origin, format);
//SolidBrush mypen = new SolidBrush(Color.Red);
//graphics1.FillPath(mypen, mygraphics);
graphics1.DrawPath(mypen, mygraphics);
graphics1.Save();