protected void Page_Load(object sender, EventArgs e)
{
DrawInclineText("万里长城永不倒");
}
private void DrawInclineText(string str)
{
if (str.Length > 0)
{
Bitmap bmp = new Bitmap(160, 30);
Graphics g = Graphics.FromImage(bmp);
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.SmoothingMode = SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.Clear(Color.Transparent);
string temp;
for (int i = 0; i < str.Length; i++)
{
temp = str.Substring(i, 1);
Matrix mat = new Matrix();//Matrix这个东西很厉害
mat.RotateAt((float)GetRandomAngle(), new PointF(20f * i, 15));//旋转
g.Transform = mat;//设置旋转
g.DrawString(temp, new Font("Arail",14f,FontStyle.Bold), new SolidBrush(Color.White), new PointF(20f * i, 2));
}
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
bmp.Dispose();
g.Dispose();
}
}
/// <summary>
/// 获取随机角度
/// </summary>
/// <returns></returns>
private int GetRandomAngle()
{
Random rand = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(50);//这里如果程序执行太快,就会产生相同的随机数,所以需要延时。
int tmp = rand.Next(-20, 20);
return tmp;
}
绘制倾斜文字的ASP.NET示例
1889

被折叠的 条评论
为什么被折叠?



