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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
雷峰网
雷峰网
量子位
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
T
Tailwind CSS Blog
月光博客
月光博客
博客园 - 【当耐特】
博客园_首页
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 广思

IIS中加入piwik跟踪代码 注册表中启用对没有标记为安全的 ActiveX 控件进行初始化和脚本运行 安装Qvode后,在IE8的菜单工具中会出现《彩票》 TRUNCATE 删除表内所有记录 Windows Server 2003 SP1本机访问报错-环回检查 通过Object传递参数 SQL Server 镜像部署 使用stsadm.exe工具实现SharePoint网站备份还原 不能打开文件:mk:@MSITStore:路径[cannot open the file mk@MSITstore:路径]解决办法 转 取得 SharePoint 中列表的Guid和列表视图的Guid (List's Guid and List View Guid) 安装Active Directory Tools For SharePoint 后无法添加到页面的原因 DirectoryEntry所有字段对应解释 windows picture and fax viewer 失效 验证配置设置时发生错误,已引发类型为System.Runtime.InteropServices.COMException的异常。其他异常信息:系统找不到指定的路径 Error message when you try to install a SQL Server 2005 service pack or a SQL Server 2005 hotfix package: "Error 29528. The setup has encountered an unexpected error while Setting Internal Properties" Excel With ADO.NET:Cannot modify the design of table ‘xxx′. It is in a read-only database 常用MSSQL语句:每个表大小,某个表所有列 Sql Server备份到远程服务器的另一种方法 查看 MSSQL 中数据表大小的方法
将字符串写入图片
广思 · 2009-11-11 · via 博客园 - 广思

将字符串写入到图片中.

1 换行采用指定写入位置来实现

2 务必释放资源,否则会出现Win32Error 

 protected void Page_Load(object sender, EventArgs e)
        {
            
if (!IsPostBack)
            {
                
//前一页面传递过来的参数
                string email = Request.QueryString.Get("email");
                
string realName = new OLUserService.OLUserService().GetRealNameByEmail(email);
                
string workid = new OLUserService.OLUserService().GetWorkIdByEmail(email);//image1图片控件-呈现写入字符串后的图片
                string fileName = this.image1.ImageUrl;
                
int index = fileName.LastIndexOf(".");string newFileName = fileName.Substring(0, index) + "_" + realName + fileName.Substring(index);
                FileInfo fileInfo 
= new FileInfo(Server.MapPath(fileName));
                fileInfo.CopyTo(Server.MapPath(newFileName), 
true);

                System.Drawing.Image image 

= new Bitmap(Server.MapPath(newFileName));
                Graphics g 
= Graphics.FromImage(image);
                
                
string s2 = string.Format("通过了关于《集团商业行为准则》的{0}", DateTime.Now.ToString("yyyy"));
                
string s3 = "年度认证,特此证明。";

                Font drawFont 

= new Font("Arial"12);
                SolidBrush drawBrush 
= new SolidBrush(Color.Black);
                
                
//通过指定写入位置实现换行功能
                drawPoint = new PointF(50200);
                g.DrawString(s2, drawFont, drawBrush, drawPoint);

                drawPoint 

= new PointF(50230);
                g.DrawString(s3, drawFont, drawBrush, drawPoint);
               

                System.Drawing.Image img 

= new Bitmap(image);
                
//此处尤为重要,使用资源后的释放.否则会出现Win32错误//[ExternalException (0x80004005): A generic error occurred in GDI+.]

                g.Dispose();
                image.Dispose();

                img.Save(Server.MapPath(newFileName), System.Drawing.Imaging.ImageFormat.Jpeg);

this.image1.ImageUrl = newFileName;
            }
        }