惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
V
V2EX
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
B
Blog
博客园 - 叶小钗
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
A
About on SuperTechFans
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog

博客园 - 偶然微笑

asp.net 登陆 asp.net获取URL和IP地址 ASP.NET获取IP与MAC地址的方法 ASP.NET获取IP的6种方法 - 偶然微笑 - 博客园 MS SQL Server 2005 通用分页存储过程 又快又简单的sql2005分页存储过程 SQL SERVER 2005分页存储过程 C#区别和认识四个判等函数 C#中数字日期转中文日期 C#算法(一)选择排序 创建基于ASP.NET的SMTP邮件服务 url传递中文的解决方案总结 C#如何取硬件标志 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie 提取HTML代码中文字的C#函数 Asp.Net输出数据到EXCEL中 ASP.NET URL Rewrite. URL重写 asp.net采集函数(采集、分析、替换、入库) .net 无限级分类
把文字变成图片的小程序
偶然微笑 · 2008-09-20 · via 博客园 - 偶然微笑

前几天看到老师展示了一个例子,是把你输入的文字转化成图片,觉得很有趣,所以今天我也做了一个小例子。在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");        
    } 
}