zoukankan      html  css  js  c++  java
  • 输出一张自定义文字的图片

      /// <summary>
            /// 返回图片
            /// </summary>
            /// <param name="img"></param>
            /// <returns></returns>
    
            protected FileContentResult RelsultBitmap(Bitmap img)
            {
                using (Bitmap bt = img)
                {
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        bt.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                        return File(ms.ToArray(), "FrameImages/Gif");
                    }
                }
            }
    
    
            /// <summary>
            /// 提示图片返回
            /// </summary>
            /// <param name="keyWord">提示文字</param>
            protected FileContentResult TipsImage(string keyWord)
            {
                int fontSize = 15;
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Center;
                using (Bitmap img = new Bitmap(288, 288))
                {
                    float y = img.Height / (keyWord.Length + 1);
                    using (Graphics g = Graphics.FromImage(img))
                    {
                        g.Clear(Color.White);//绘画背景颜色   
                        for (int i = 0; i < keyWord.Length; i++)
                        {
                            // 绘画文字   
                            g.DrawString(keyWord[i].ToString(), new Font("Arial", fontSize, FontStyle.Regular), Brushes.Red, (img.Width / 2) - (fontSize / 2), y * (i + 1), sf);
                        }
                        return RelsultBitmap(img);
                    }
                }
            }

    效果图:

      

  • 相关阅读:
    cogs 826. Feb11] GF打dota
    cogs 133. [USACO Mar08] 牛跑步 A*k短路算法
    luogu cogs 1437. [NOIP2013]转圈游戏
    RESTful
    中间件
    回顾基础知识,类,fbv,cbv
    Vue
    ES6的一些说明
    小试牛刀2
    小试牛刀
  • 原文地址:https://www.cnblogs.com/5tomorrow/p/11249355.html
Copyright © 2011-2022 走看看