zoukankan      html  css  js  c++  java
  • 字体辉光效果

            /// <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;
            }
  • 相关阅读:
    [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例
    玩转Asp.net MVC 的八个扩展点
    float实例讲解
    C#高性能TCP服务的多种实现方式
    如何把SQLServer数据库从高版本降级到低版本?
    ASP.NET MVC Area使用-将Area设置成独立项目
    如何使用ping和tracert命令测试网站访问速度
    ASP.NET MVC 入门10、Action Filter 与 内置的Filter实现(实例-防盗链)
    MVC Action Filter
    c#中单元测试
  • 原文地址:https://www.cnblogs.com/qq1223558/p/3410025.html
Copyright © 2011-2022 走看看