关于文本转位图(转)

本文转自 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);

 

转载于:https://www.cnblogs.com/finema/archive/2007/01/09/615454.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值