当前位置: 首页 > news >正文

aps.net的身份证背景图片

需要这样身份证号+姓名的背景图吗?下边是我造的现成的,肯定不完美,但是复制粘贴就能使:)

使用方法:img.aspx?sfz=3700001151545185X&name=李大霄

<%@ Page Language="C#"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>

<%
    /*
     * 身份证水印背景图 V1.0;
     * 
     * GuYang
     * 2016/11/25
     */

    #region fun

    Func<int, int, int, int[]> f1 = null;
    {
        f1 = (w, h, angle) =>
        {
            var an = (Math.PI / 180) * angle;
            var w1 = w - (h - w * Math.Tan(an)) * (Math.Tan(an) / (1 - Math.Pow(Math.Tan(an), 2)));
            var h1 = w1 * Math.Tan(an);
            var a = Math.Sqrt((Math.Pow(w1, 2) + Math.Pow(h1, 2)));
            var b = (h - h1) * a / w1;
            return new int[] { (int)a, (int)b };
        };
    }
    Func<Graphics, string, FontFamily, int, float[]> f2 = null;
    {
        f2 = (g, sfz, fontFamily, width) =>
        {
            if (g == null || fontFamily == null || string.IsNullOrWhiteSpace(sfz) || sfz.Length < 15 || width < 50) return new float[] { 12F, 12F };
            var font_em_size = 9F;
            var font_height = 1F;
            while (true)
            {
                var size = g.MeasureString(sfz, new Font(fontFamily, font_em_size++));
                font_height = size.Height;
                if (size.Width >= width) break;
            }
            return new float[] { font_em_size, font_height };
        };
    }
    Func<Bitmap, float, Color, Bitmap> f3 = null;
    {
        f3 = (bmp, angle, bkColor) =>
        {
            int w = bmp.Width + 2;
            int h = bmp.Height + 2;

            PixelFormat pf;

            if (bkColor == Color.Transparent) pf = PixelFormat.Format32bppArgb;
            else pf = bmp.PixelFormat;

            Bitmap tmp = new Bitmap(w, h, pf);
            Graphics g = Graphics.FromImage(tmp);
            g.Clear(bkColor);
            g.DrawImageUnscaled(bmp, 1, 1);
            g.Dispose();

            GraphicsPath path = new GraphicsPath();
            path.AddRectangle(new RectangleF(0f, 0f, w, h));
            Matrix mtrx = new Matrix();
            mtrx.Rotate(-angle);
            RectangleF rct = path.GetBounds(mtrx);

            Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
            g = Graphics.FromImage(dst);
            g.Clear(bkColor);
            g.TranslateTransform(-rct.X, -rct.Y);
            g.RotateTransform(-angle);
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(tmp, 0, 0);
            g.Dispose();

            tmp.Dispose();

            return dst;
        };
    }
    var fun = new { f1 = f1, f2 = f2,  f3 = f3,};

    #endregion

    {
        //水印图片宽度
        var width = 400;
        //try { if(!string.IsNullOrWhiteSpace(Request["width"])) width = Convert.ToInt32(Request["width"]); }
        //catch { }

        //水印图片高度
        var height =300;
        //try { if(!string.IsNullOrWhiteSpace(Request["height"])) height = Convert.ToInt32(Request["height"]); }
        //catch { }

        //水印字体倾斜角度
        var angle = 8;

        //身份证号
        var sfz = Request["sfz"];//"3700001151545185X";

        //姓名
        var name = Request["name"];//"李大霄";

        var bk_color = Color.White;
        var bk_bursh = Brushes.White;
        var font_color = Brushes.LightGray;

        var font_family = FontFamily.GenericSansSerif;
        var core_size = fun.f1(width, height, angle);
        var core_width = Math.Max(core_size[0],20);
        var core_height =Math.Max(core_size[1],8);
        var bmp = new Bitmap(core_width, core_height, PixelFormat.Format24bppRgb);
        var g = Graphics.FromImage(bmp);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.FillRectangle(bk_bursh, 0, 0, core_width, core_height);
        g.DrawRectangle(new Pen(bk_bursh), 0, 0, core_width-1, core_height-1);
        var em_size__font_height = fun.f2(g, sfz, font_family, core_width);
        var em_size = em_size__font_height[0];
        var font = new Font(font_family, em_size);
        var font_height = em_size__font_height[1];
        var line1y = (float)Math.Max(((core_height - 2 * font_height) * 0.5), 0);
        g.DrawString(sfz,font, font_color, 0, line1y);
        var line2y = (float)(line1y + font_height);
        var line2x = (float)Math.Max((core_width - g.MeasureString(name, font).Width) * 0.5, 0);
        g.DrawString(name, font, font_color, line2x, line2y);
        bmp = fun.f3(bmp, angle, bk_color);
        var ms = new MemoryStream();
        bmp.Save(ms, ImageFormat.Jpeg);
        Response.ContentType = "image/jpeg";
        Response.BinaryWrite(ms.ToArray());
    }
%>

 

转载于:https://www.cnblogs.com/flyGy/p/9489403.html

相关文章:

  • matlab怎么画lnx图像,inx图像(lnx的图像函数)
  • matlab计算结果中特别长,matlab运算结果太长Output truncated. Text exceeds maximum line length o......
  • java之注解
  • php 参数 过滤 类,参数过滤类
  • 还是畅通工程(HDU 1233)
  • mysql多表查询基础命令,MySql多表查询命令
  • B - Battle City bfs+优先队列
  • python中使用关键字声明一个函数,Python函数的说明与运用
  • BZOJ 3787 Gty的文艺妹子序列(分块+树状数组+前缀和)
  • 如何创建一个oracle新用户,如何创建Oracle新用户(新schema)
  • The.Glory.of.Innovation 创新之路2科学基石
  • oracle 增加 dbwr 性能,读书笔记-高级owi与oracle性能调整-io
  • c add oracle,oracle部署部分整理
  • 点分治题单(来自XZY)
  • php潜在因子推荐算法,潜在因子(Latent Factor)推荐算法—音乐推荐
  • __proto__ 和 prototype的关系
  • 《剑指offer》分解让复杂问题更简单
  • go语言学习初探(一)
  • java多线程
  • LeetCode29.两数相除 JavaScript
  • LeetCode算法系列_0891_子序列宽度之和
  • Mysql优化
  • Odoo domain写法及运用
  • thinkphp5.1 easywechat4 微信第三方开放平台
  • 将回调地狱按在地上摩擦的Promise
  • 每天10道Java面试题,跟我走,offer有!
  • 前端_面试
  • 山寨一个 Promise
  • 设计模式(12)迭代器模式(讲解+应用)
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • 基于django的视频点播网站开发-step3-注册登录功能 ...
  • ​LeetCode解法汇总1276. 不浪费原料的汉堡制作方案
  • #《AI中文版》V3 第 1 章 概述
  • #define与typedef区别
  • #控制台大学课堂点名问题_课堂随机点名
  • $.ajax,axios,fetch三种ajax请求的区别
  • (a /b)*c的值
  • (C++)栈的链式存储结构(出栈、入栈、判空、遍历、销毁)(数据结构与算法)
  • (zt)最盛行的警世狂言(爆笑)
  • (动手学习深度学习)第13章 计算机视觉---微调
  • (规划)24届春招和25届暑假实习路线准备规划
  • (离散数学)逻辑连接词
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • .class文件转换.java_从一个class文件深入理解Java字节码结构
  • .NET Remoting Basic(10)-创建不同宿主的客户端与服务器端
  • .net 程序发生了一个不可捕获的异常
  • .NET6使用MiniExcel根据数据源横向导出头部标题及数据
  • .NET连接MongoDB数据库实例教程
  • @ModelAttribute 注解
  • @param注解什么意思_9000字,通俗易懂的讲解下Java注解
  • @SpringBootApplication 包含的三个注解及其含义
  • [3D游戏开发实践] Cocos Cyberpunk 源码解读-高中低端机性能适配策略
  • [AIGC] Redis基础命令集详细介绍