文字生成图片html,根据文字生成图片

下面这个应用代码主要用于模拟POST请求后返回结果,然后正则匹配可能出现的文字或图片,如果是文字则生成图片,如果是图片则直接下。关键代码如下:

Regex reg = new Regex(@”(?.*?)”);

stringDic[“test”]=”0″;

MatchCollection match=reg.Matches(stringDic[“backhtml”]);

listDic[“testlist”].Clear();

foreach(Match mt in match)

{

Random ran = new Random(GetRandomSeed());

string RandKey = ran.Next(0, 99999999).ToString().PadLeft(8,’0′);

string filename=DateTime.Now.Ticks.ToString()+RandKey+”.gif”;

try

{

if (!Directory.Exists(stringDic[“rootpath”]+@”:\\Temp\\erfenzi\\”+stringDic[“关键词”]+”\\”))//如果不存在就创建 dir 文件夹

Directory.CreateDirectory(stringDic[“rootpath”]+@”:\\Temp\\erfenzi\\”+stringDic[“关键词”]+”\\”);

}

catch{}

listDic[“testlist”].Add(filename);

if(mt.Groups[“mycontent”].Value.ToString().Contains(“

{

Regex reg2=new Regex(@”(?<mypic[^ ]*?) width=30>”);

try{

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;//.Ssl3;//.Tls12; //加上这一句

System.Net.WebRequest webreq = System.Net.WebRequest.Create(“http://XXXXXXX.com/”+reg2.Match(mt.Groups[“mycontent”].Value.ToString()).Groups[1].Value.ToString());

System.Net.WebResponse webres = webreq.GetResponse();

Stream stream = webres.GetResponseStream();

Image.FromStream(stream).Save(stringDic[“rootpath”]+@”:\\Temp\\erfenzi\\”+stringDic[“关键词”]+”\\”+filename);

}

catch{}

}

else

{

string text =System.Net.WebUtility.HtmlDecode(mt.Groups[“mycontent”].Value.ToString().Trim());

//得到Bitmap(传入Rectangle.Empty自动计算宽高)

try{

Bitmap bmp = TextToBitmap(text,new Font(new FontFamily(“微软雅黑”), 52), Rectangle.Empty, Color.Black, Color.White);

//保存到桌面save.jpg

string directory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);

bmp.Save(stringDic[“rootpath”]+@”:\\Temp\\erfenzi\\”+stringDic[“关键词”]+”\\”+filename, System.Drawing.Imaging.ImageFormat.Jpeg);

}

catch{}

}

}

stringDic[“test”]=match.Count>0?”yes”:”no”;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值