无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
namespace Chen
{
public class warterfont
{
public void addtexttoimg(string filename, string text)
{
if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(filename)))
{
throw new FileNotFoundException("the file don't exist!");
}
if (text == string.Empty)
{
return;
}
//还需要判断文件类型是否为图像类型,这里就不赘述了
Image image = Image.FromFile(System.Web.HttpContext.Current.Server.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); //输出处理后的图像,这里为了演示方便,我将图片显示在页面中了
bitmap.Save(System.Web.HttpContext.Current.Server.MapPath("/" + "aa.jpg"), ImageFormat.Jpeg); //保存到磁盘上
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "image/jpeg";
System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray());
g.Dispose();
bitmap.Dispose();
image.Dispose();
}
}
}

标签:
C#,文字水印类

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。