排名
1
文章
860
粉丝
112
评论
163
.net core自定义项目模板,创建自己的模板项目,使用命令行创建模板项目
尘叶心繁 : 可以可以讲真的我都想弄个模板
net core webapi post传递参数
庸人 :
确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 : 已精
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 :
疯狂反射
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

handler代码如下:
- public class CodeHandler : IHttpHandler,IRequiresSessionState
- {
-
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "image/png";
-
- Bitmap bt = new Bitmap(100, 36);
-
- //通过图片拿到图片的画笔类
- Graphics gp = Graphics.FromImage(bt);
-
- //填充一个背景颜色
- gp.FillRectangle(new SolidBrush(Color.Black), 0, 0, 100, 36);
-
- //产生一个字符串
- string codestr = "";
- //构建大写小写与数字
- List<int> codelist = new List<int>();
- for (int i = 97, j = 65; i <= 122; i++, j++)
- {
- codelist.Add(i);
- codelist.Add(j);
- }
- for (int i = 48; i <= 57; i++)
- {
- codelist.Add(i);
- }
-
- //随机因子,随时因子一样随机数就一样,默认随机因子是时间
- //for (int i = 0; i < 4; i++)
- //{
- // Random random = new Random(Guid.NewGuid().GetHashCode());
- // int code = (char)random.Next(48, 123);
- // if (!codelist.Contains(code))
- // {
- // i--;
- // continue;
- // }
- // codestr += (char)code;
- //}
-
- string codeStr = "";
- Random random = new Random();
- for (int i = 0; i < 4; i++)
- {
- int charindex = random.Next(0, codeList.Count);
- codeStr += (char)codeList[charindex];
- }
- graphics.DrawString(codeStr, font, solidBrush, 25, 8);
-
- //产生干扰下
- for (int i = 0; i < 3; i++)
- {
- gp.DrawLine(new Pen(Color.White, 1), random2.Next(0, 100), random2.Next(0, 36), random2.Next(0, 100), random2.Next(0, 36));
- }
-
- //产生小字干扰
- for (int i = 0; i < 10; i++)
- {
- Random random = new Random(Guid.NewGuid().GetHashCode());
-
- int code = (char)random.Next(48, 123);
- if (!codelist.Contains(code))
- {
- i--;
- continue;
- }
- char lcode = (char)code;
-
- gp.DrawString(lcode+"", new Font("宋体", 8), new SolidBrush(Color.White), random2.Next(0, 100), random2.Next(0, 36));
- }
-
- context.Session["codestr"] = codestr;
-
- bt.Save(context.Response.OutputStream, ImageFormat.Png);
- }
-
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
效果如下:
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价