字体辉光效果

        /// <summary>
        /// 字体辉光效果
        /// </summary>
        /// <param name="text">要处理的文字</param>
        /// <param name="font">字体样式</param>
        /// <param name="fontColor">文字颜色</param>
        /// <param name="effectColor">辉光颜色</param>
        /// <param name="scope">范围</param>
        /// <returns></returns>
        public static Image ImageLightEffect(string text, Font font, Color fontColor, Color effectColor, int scope)
        {
            Bitmap bitmap = null;//实例化Bitmap类
            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))//实例化Graphics类
            {
                SizeF size = g.MeasureString(text, font);//对字符串进行测量
                using (Bitmap bmp = new Bitmap((int)size.Width, (int)size.Height))//通过文字的大小实例化Bitmap类
                using (Graphics bmpG = Graphics.FromImage(bmp))//实例化Bitmap类
                using (SolidBrush sbBack = new SolidBrush(Color.FromArgb(16, effectColor.R, effectColor.G, effectColor.B)))//根据RGB的值定义画刷
                using (SolidBrush sbFore = new SolidBrush(fontColor))//定义画刷
                {
                    bmpG.SmoothingMode = SmoothingMode.HighQuality;//设置为高质量
                    bmpG.InterpolationMode = InterpolationMode.HighQualityBilinear;//设置为高质量的收缩
                    bmpG.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;//消除锯齿
                    bmpG.DrawString(text, font, sbBack, 0, 0);//给制文字
                    bitmap = new Bitmap(bmp.Width + scope, bmp.Height + scope);//根据辉光文字的大小实例化Bitmap类
                    using (Graphics bitmapG = Graphics.FromImage(bitmap))//实例化Graphics类
                    {
                        bitmapG.SmoothingMode = SmoothingMode.HighQuality;//设置为高质量
                        bitmapG.InterpolationMode = InterpolationMode.HighQualityBilinear;//设置为高质量的收缩
                        bitmapG.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;//消除锯齿
                        //遍历辉光文字的各象素点
                        for (int x = 0; x <= scope; x++)
                        {
                            for (int y = 0; y <= scope; y++)
                            {
                                bitmapG.DrawImageUnscaled(bmp, x, y);//绘制辉光文字的点
                            }
                        }
                        bitmapG.DrawString(text, font, sbFore, scope / 2, scope / 2);//绘制文字
                    }
                }
            }

            return bitmap;
        }

 

posted @ 2013-11-06 10:55  Micmacs  阅读(536)  评论(0编辑  收藏  举报