|
绘制每个字符
由于每个字符所在的点以及相对于圆心的角度都已经计算出来,那么进行绘制就相对简单多了,这里只是通过Matrix来转换一下坐标而已。
具体代码如下。
/// <summary>
/// Draw every rotated character
/// </summary>
/// <param name="g"></param>
/// <param name="_text"></param>
/// <param name="_angle"></param>
/// <param name="_PointCenter"></param>
private void DrawRotatedText( Graphics g, string _text, float _angle, PointF _PointCenter )
{
// Init format
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
// Create graphics path
GraphicsPath gp = new GraphicsPath( System.Drawing.Drawing2D.FillMode.Winding );
int x = (int)_PointCenter.X;
int y = (int)_PointCenter.Y;
// Add string
gp.AddString( _text, _font.FontFamily, (int)_font.Style,
_font.Size, new Point( x, y ), sf );
// Rotate string and draw it
Matrix m = new Matrix();
m.RotateAt( _angle, new PointF( x,y ) );
g.Transform = m;
g.DrawPath( new Pen( _color), gp );
g.FillPath( new SolidBrush( _fillcolor ), gp );
}
以上就是绘制印章的核心算法。对于这个类的调用,如下即可。
TextOnSeal _top = new TextOnSeal();
_top.TextFont = new Font("宋体", 16, FontStyle.Regular);
_top.FillColor = Color.Red;
_top.ColorTOP = Color.Black;
_top.Text = "中华人民共和国";
_top.BaseString = "愚翁专用章";
_top.ShowPath = true;
_top.LetterSpace = 20;
_top.SealSize = 180;
_top.CharDirection = Char_Direction.Center;
_top.SetIndent( 20 );
Graphics g = this.CreateGraphics();
g.DrawImage( _top.TextOnPathBitmap(), 0, 0 );
_top.CharDirection = Char_Direction.ClockWise;
g.DrawImage( _top.TextOnPathBitmap(), 180, 0 );
_top.CharDirection = Char_Direction.AntiClockWise;
g.DrawImage( _top.TextOnPathBitmap(), 0, 180 );
_top.SetIndent( 20 );
_top.CharDirection = Char_Direction.OutSide;
g.DrawImage( _top.TextOnPathBitmap(), 180, 180 );
通过如上的代码,可以得到如下的效果。

其实如果做印章来说,还有很多地方需要细化,那么如果网友对此有兴趣,可以在我的基础上进行扩展,在此我就不一一述说。
共8页: 上一页 [1] [2] 3 [4] [5] [6] [7] [8] 下一页
|