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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
博客园 - 司徒正美
L
LangChain Blog
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
月光博客
月光博客
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net

博客园 - 偶然微笑

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");        
    } 
}