闪光文字
源文件:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace flash
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap bmpText;
private void timer1_Tick(object sender, EventArgs e)
{
Random rand = new Random();
Color clr1 = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
Color clr2 = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
using (Font fnt = new Font("Arial", 25, FontStyle.Bold))
{
this.bmpText = (Bitmap)FancyText.ImageFromText("图书销售管理系统", fnt, clr1, clr2);
}
this.pictureBox_Title.Image = this.bmpText;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
FancyText.cs类的代码:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Collections.Generic;
using System.Text;
namespace flash
{
class FancyText
{
private const int blurAmount = 5;
public static Image ImageFromText(string strText, Font fnt, Color clrFore, Color clrBack)
{
Bitmap bmpOut = null;
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
SizeF sz = g.MeasureString(strText, fnt);
using (Bitmap bmp = new Bitmap((int)sz.Width, (int)sz.Height))
using (Graphics gBmp = Graphics.FromImage(bmp))
using (SolidBrush brBack = new SolidBrush(Color.FromArgb(16, clrBack.R, clrBack.G, clrBack.B)))
using (SolidBrush brFore = new SolidBrush(clrFore))
{
gBmp.SmoothingMode = SmoothingMode.HighQuality;
gBmp.InterpolationMode = InterpolationMode.HighQualityBilinear;
gBmp.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
gBmp.DrawString(strText, fnt, brBack, 0, 0);
bmpOut = new Bitmap(bmp.Width + blurAmount, bmp.Height + blurAmount);
using (Graphics gBmpOut = Graphics.FromImage(bmpOut))
{
gBmpOut.SmoothingMode = SmoothingMode.HighQuality;
gBmpOut.InterpolationMode = InterpolationMode.HighQualityBilinear;
gBmpOut.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
//阴影光晕
for (int x = 0; x <= blurAmount; x++)
{
for (int y = 0; y <= blurAmount; y++)
{
gBmpOut.DrawImageUnscaled(bmp, x, y);
}
}
gBmpOut.DrawString(strText, fnt, brFore, blurAmount / 2, blurAmount / 2);
}
}
}
return bmpOut;
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jingang123gz/archive/2007/11/17/1889433.aspx

浙公网安备 33010602011771号