无为清净楼资源网 Design By www.qnjia.com
using System.Drawing; using System.IO; using System.Drawing.Imaging; private void AddTextToImg(string fileName,string text) { if(!File.Exists(MapPath(fileName))) { throw new FileNotFoundException("The file don't exist!"); } if( text == string.Empty ) { return; } //还需要判断文件类型是否为图像类型,这里就不赘述了 System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(fileName)); Bitmap bitmap = new Bitmap(image,image.Width,image.Height); Graphics g = Graphics.FromImage(bitmap); float fontSize = 12.0f; //字体大小 float textWidth = text.Length*fontSize; //文本的长度 //下面定义一个矩形区域,以后在这个矩形里画上白底黑字 float rectX = 0; float rectY = 0; float rectWidth = text.Length*(fontSize+8); float rectHeight = fontSize+8; //声明矩形域 RectangleF textArea = new RectangleF(rectX,rectY,rectWidth,rectHeight); Font font = new Font("宋体",fontSize); //定义字体 Brush whiteBrush = new SolidBrush(Color.White); //白笔刷,画文字用 Brush blackBrush = new SolidBrush(Color.Black); //黑笔刷,画背景用 g.FillRectangle(blackBrush,rectX,rectY,rectWidth,rectHeight); g.DrawString(text,font,whiteBrush,textArea); MemoryStream ms = new MemoryStream( ); //保存为Jpg类型 bitmap.Save(ms,ImageFormat.Jpeg); //输出处理后的图像,这里为了演示方便,我将图片显示在页面中了 Response.Clear(); Response.ContentType = "image/jpeg"; Response.BinaryWrite( ms.ToArray() ); g.Dispose(); bitmap.Dispose(); image.Dispose(); }
调用时很简单,
AddTextToImg("me.jpg","程序人生http://www.manong123.com/");
一切OK了,感觉.net确实好强大,这些功能在Asp中可是奢侈品了,而在.Net环境中却能轻而易举的完成!
标签:
Asp.net,水印
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍