Asp.NET把文字变成图片的小程序

前几天看到老师展示了一个例子,是把你输入的文字转化成图片,觉得很有趣,所以今天我也做了一个小例子。在Doc下输入文字,然后会在你要求的目录下生成一张图片。当然字体颜色,图片大小都是可以自己设定的,代码比较少。

using system;
using system.Collections.Generic;
using system.Drawing;
using system.Drawing.Imaging; 
public class Drawing
{    
    public void CreateImage(string name,string filePath)
    {
        int wid=400;
        int high=200;
        Font font=new Font("Arial",48,FontStyle.Bold);
        //绘笔颜色
        SolidBrush brush=new SolidBrush(Color.Black);
        
        Bitmap image=new Bitmap(wid,high);
        Graphics g=Graphics.FromImage(image);
        g.Clear(ColorTranslator.FromHtml("#f0f0f0"));
        RectangleF rect=new RectangleF(5,2,wid,high);
        //绘制图片
        g.DrawString(name,font,brush,rect);
        //保存图片
        image.Save(filePath,ImageFormat.Jpeg);
        //释放对象
        g.Dispose();
        image.Dispose();
    }
}
public class Program
{
    public static void Main()
    {
        Drawing dh=new Drawing();
        Console.WriteLine("输入你的名字:");
        string name=Console.ReadLine();
        dh.CreateImage(name,@"D:\test\c#\advanced\Name.jpg");        
    } 
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值