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

编程入门 行业动态 更新时间:2024-10-11 09:24:37

<a href=https://www.elefans.com/category/jswz/34/1769559.html style=文字生成图片html,根据文字生成图片"/>

文字生成图片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(@”[^ ]*?) width=30>”);

try{

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

System.Net.WebRequest webreq = System.Net.WebRequest.Create(“/”+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”;

更多推荐

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

本文发布于:2023-06-24 01:42:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/857555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文字   图片   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!