|
/// <summary>
/// Generate seal bitmap
/// </summary>
/// <returns></returns>
public Bitmap TextOnPathBitmap()
{
// Create bitmap and graphics
Bitmap bit = new Bitmap( _rect.Width, _rect.Height );
Graphics g = Graphics.FromImage( bit );
// Compute string length in graphics
float[] fCharWidth = new float[_text.Length];
float fTotalWidth = ComputeStringLength( _text, g, fCharWidth, _letterspace, _chardirect );
// Compute arc's start-angle and end-angle
double fStartAngle, fSweepAngle;
fSweepAngle = fTotalWidth * 360 / ( _rectcircle.Width * Math.PI );
fStartAngle = 270 - fSweepAngle / 2;
// Compute every character's position and angle
PointF[] pntChars = new PointF[ _text.Length ];
double[] fCharAngle = new double[ _text.Length ];
ComputeCharPos( fCharWidth, pntChars, fCharAngle, fStartAngle );
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
DrawSealBase( g );
// Draw every character
for( int i = 0; i < _text.Length; i++ )
DrawRotatedText( g, _text[i].ToString(), (float)(fCharAngle[i] + _degree), pntChars[i] );
g.Dispose();
// Return bitmap
return bit;
}
/// <summary>
/// Draw seal base
/// </summary>
/// <param name="g"></param>
private void DrawSealBase( Graphics g )
{
// Draw background
g.FillRectangle( Brushes.Black, _rect );
g.FillEllipse( new SolidBrush( _fillcolor ),
new Rectangle( 1,1, _rect.Width - 2, _rect.Height - 2 ) );
g.FillEllipse( Brushes.White,
new Rectangle( 4, 4, _rect.Width - 8, _rect.Height - 8 ) );
// Draw start signal
StringFormat sf = new StringFormat();
string strStar = "★";
Font fnt = new Font( _font.FontFamily, _font.Size * 3 );
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
SizeF siz = g.MeasureString( strStar, fnt );
g.DrawString( strStar, fnt, new SolidBrush( _fillcolor ),
new RectangleF( _rect.Width / 2 - siz.Width / 2,
_rect.Height / 2 - siz.Height/ 2,
siz.Width, siz.Height ), sf );
// Draw base string
float[] fCharWidth = new float[_basestring.Length];
float fTotalWidths = ComputeStringLength( _basestring, g, fCharWidth, 0,
Char_Direction.Center );
float fLeftPos = ( _rect.Width - fTotalWidths ) / 2;
PointF pt;
for( int i = 0; i < _basestring.Length; i++ )
{
pt = new PointF( fLeftPos + fCharWidth[i] / 2,
_rect.Height / 2 + siz.Height / 2 + 10 );
DrawRotatedText( g, _basestring[i].ToString(), 0, pt );
fLeftPos += fCharWidth[i];
}
}
共8页: 上一页 [1] [2] [3] [4] [5] [6] 7 [8] 下一页
|