zoukankan      html  css  js  c++  java
  • C# GDI+ 文字 阴影,描边 的实现

    好的,各位RT 这次是简单的 C# GDI+ 文字描边的实现。。。。
    这次不使用先进的东西。。。。
    先看效果图,如下:
    当然,你自己动手做出的效果我想会更好。我只是抛砖引玉而已,呵呵。
     
                this.Paint += Form1_Paint;//这个写在Form_load事件里面
            
    
            void Form1_Paint(object sender, PaintEventArgs e)
            {
                //Graphics g = e.Graphics;
                //string s = "Outline";
                //RectangleF rect = this.ClientRectangle;
                //Font font = this.Font;
                //StringFormat format = StringFormat.GenericTypographic;
                //float dpi = g.DpiY;
                //using (GraphicsPath path= GetStringPath(s, dpi, rect, font, format))
                //{
                //    g.DrawPath(Pens.Black, path);
                //}
    
    
                Graphics g = e.Graphics;
                string s = "宋体宋体宋体宋体宋体宋体宋体宋体宋体";
                RectangleF rect = new RectangleF(350, 0,400,200);
                Font font = this.Font;
                StringFormat format = StringFormat.GenericTypographic;
                float dpi = g.DpiY;
                using (GraphicsPath path = GetStringPath(s, dpi, rect, font, format))
                {
                    //阴影代码
                    //RectangleF off = rect;
                    //off.Offset(5, 5);//阴影偏移
                    //using (GraphicsPath offPath = GetStringPath(s, dpi, off, font, format))
                    //{
                    //    Brush b = new SolidBrush(Color.FromArgb(100, 0, 0, 0));
                    //    g.FillPath(b, offPath);
                    //    b.Dispose();
                    //}
                    g.SmoothingMode = SmoothingMode.AntiAlias;//设置字体质量
                    g.DrawPath(Pens.Black, path);//绘制轮廓(描边)
                    g.FillPath(Brushes.White, path);//填充轮廓(填充)
                }
    
            }
    
    
    
    
            GraphicsPath GetStringPath(string s, float dpi, RectangleF rect, Font font, StringFormat format)
            {
                GraphicsPath path = new GraphicsPath();
                // Convert font size into appropriate coordinates
                float emSize = dpi * font.SizeInPoints / 72;
                path.AddString(s, font.FontFamily, (int)font.Style, emSize, rect, format);
    
                return path;
            }
    需要阴影的同学 上面的注释去掉就ok。
     
    好吧。没啥可说的,很多人都会。
    欢迎交流。。。
    by cnblogs Soar
     
     
     
  • 相关阅读:
    netcore一键部署到linux服务器以服务方式后台运行
    查找100-999之间的水仙花数
    shell创建数据库的脚本
    python打印九九乘法表的菱形实现
    c++一些重要的细节
    MySQL数据库基础学习笔记(二)
    MySQL数据库基础学习笔记(一)
    react-redux 的基本使用
    react-router-dom基本使用+3种传参方式
    从create-react-app 项目搭建开始
  • 原文地址:https://www.cnblogs.com/SHGF/p/2995021.html
Copyright © 2011-2022 走看看