zoukankan      html  css  js  c++  java
  • 关于文本转位图(转)

    本文转自 microsoft.public.dotnet.languages.csharp
    主题:how convert text to bitmap...
    日期:2007年1月9日 7:07

    I found a sweet url here...
    http://www.devasp.net/net/articles/display/139.html

    and here it is, converted to C#, slightly modified


    using System.Drawing;
    using System.Drawing.Imaging;

    string FontName = "Courier New";
                Color FontColor = Color.Black;
                Color BackColor = Color.White;
                int FontSize = 14;
                int Width = 25;

               //fontsize times 1.5 is just high enough
               //to encase the text without spacer above or below.
                float h = (FontSize * 1.5f);
                int Height = int.Parse(h.ToString());

                //file to save as
                string FileName = "MyImage";

                //fore color
                SolidBrush objBrushForeColor = new SolidBrush(FontColor);

               //back color
                SolidBrush objBrushBackColor = new SolidBrush(BackColor);

               //the point to start the text. I chose horizontal value of zero
              //vertical starts at 2 pixels down.
                Point objPoint = new Point(0,2);

               //font object
                Font objFont = new Font(FontName, FontSize);
               
                //bitmap object
                Bitmap objBitmap = new Bitmap(Width, Height);

               //graphics object
                Graphics objGraphics =
    System.Drawing.Graphics.FromImage(objBitmap);

                 //the following line is not needed, but is shown
                //in the vb example.. dont know why.
                //Color objColor;

                //draw a white rectangle
                objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width,
    (FontSize*1.5f));
               
    //draw the text
    objGraphics.DrawString(character.ToString(), objFont, objBrushForeColor,
    objPoint);

    //save the bitmap.
                objBitmap.Save(FileName + ".bmp", ImageFormat.Bmp);

  • 相关阅读:
    IDEA Rider Express expected
    .netCore与Framework相同位数下生成的hashcode是不一样的
    IDEA Rider代码错误提示关闭
    VS C# 项目一个解决方案包含多个git库项目问题
    Git Updates were rejected because the tip of your current branch is behind 一例解决方案
    IISExpress 管道模式、集成模式切换
    vs 下TGIT插件
    git常用命令
    自建git项目管理库及ssh方式使用
    Ext.net store数据加载事件
  • 原文地址:https://www.cnblogs.com/finema/p/615454.html
Copyright © 2011-2022 走看看