2019独角兽企业重金招聘Python工程师标准>>>

一、实现方法如下

1、IDCardGenerate.java

public interface IDCardGenerate {//public static final String outPath = "D:/gen/idcard.png";//public static final String outDir = "D:/gen/";//接口的定义,接口里只包含常量和抽象方法.public static final String outPath = ".\\idcard.png";//这个是临时文件名public static final String outDir = ".\\";public static final String outSuf = ".jpg";public static final int canvasWidth = 480;public static final int canvasHeight = 320;public static final int imgWidth = 270;public static final int imgHeigth = 428;public static final int xStart = 60;public static final int yStart = 85;public static final int yStep = 32;public static final int xStep = 90;public static final int charSpace = 10;public static final int paramXStart = 110;public static final int nationSpace = 140;public static final int monthSpace = 120;public static final int daySpace = 60;public static final int idNoSpace = 80;public static final int charLineSpace = 25;public void paint();
}

2、IDCardGeneratorFront .java

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;import javax.imageio.ImageIO;public class IDCardGeneratorFront implements IDCardGenerate {private IDCardInfo idCard = null;@SuppressWarnings("unused")private IDCardGeneratorFront(){}public IDCardGeneratorFront(IDCardInfo idCard) throws Exception{if(null == idCard){throw new Exception("IDCardinfo object can not be null!");}this.idCard = idCard;}@Overridepublic void paint(){BufferedImage bi = new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_ARGB);//构造一个类型为预定义图像类型之一的 BufferedImageGraphics2D g2d = getTemplateFront(bi);Font font = new Font("华文细黑",Font.BOLD,16);//可不定义g2d.setPaint(Color.black);//给写入的个人信息文本设置为黑色//g2d.setFont(font);int ypStep = 0;int xpStep = 0;//姓名参数g2d.drawString(idCard.getName(), paramXStart, yStart);//性别参数ypStep = yStart + yStep;g2d.drawString(idCard.getSex(), paramXStart, ypStep);//民族参数xpStep = xStart + nationSpace;g2d.drawString(idCard.getNation(), xpStep, ypStep);//出生参数//幄1�7ypStep += yStep;g2d.drawString(idCard.getBornYear(), paramXStart, ypStep);//朄1�7xpStep = xStart + monthSpace;g2d.drawString(idCard.getBornMonth(), xpStep, ypStep);//旄1�7xpStep += daySpace;g2d.drawString(idCard.getBornDay(), xpStep, ypStep);//住址参数ypStep += yStep;g2d.drawString(idCard.getAddr1(), paramXStart, ypStep);//地址换行处理g2d.drawString(idCard.getAddr2(), paramXStart, ypStep + charLineSpace);//身份证号ypStep += idNoSpace;xpStep = xpStep - daySpace;//font = new Font(Font.MONOSPACED,Font.BOLD,20);//g2d.setFont(font);g2d.drawString(idCard.getIdNo(), xpStep, ypStep + 10);g2d.dispose();try {ImageIO.write(bi, "PNG", new File(outPath));// 使用支持给定格式的任意 ImageWriter 将一个图像写入 FileFile imgFile = new File(outPath);//通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。String imgName = String.valueOf(System.currentTimeMillis());imgFile.renameTo(new File(outDir + imgName + outSuf));//重新命名此抽象路径名表示的文件。} catch (IOException e) {e.printStackTrace();} finally{} } private Graphics2D getTemplateFront(BufferedImage bi) {//该方法是用来获取模板样式Graphics2D g2d = bi.createGraphics();int ypStep = 0;int xpStep = 0;Font font = new Font("黑体",Font.BOLD,14);//设置背景艄1�7g2d.setBackground(Color.white);//白色背景g2d.clearRect(0, 0, canvasWidth, canvasWidth);//g2d.fillRect(0, 0, canvasWidth, canvasWidth);//绘制圆角矩形g2d.setPaint(Color.black);//矩形边框颜色RoundRectangle2D rr = new RoundRectangle2D.Double(30,30,428,270,20,20);//设置圆角g2d.draw(rr);//要呈现的轮廓//姓名g2d.setPaint(Color.BLUE);//这是为模板字体设置为蓝色//g2d.setFont(font);//调试用的//姓名g2d.drawString("姓名", xStart, yStart);//首字符的基线位于用户空间的1�7 (x, y) 位置处1�7ypStep = yStart + yStep;//性 别g2d.drawString("性 别", xStart, ypStep);//pStep += yStep;//民 族xpStep =xStart + xStep;g2d.drawString("民 族",xpStep , ypStep);ypStep += yStep;//出 生g2d.drawString("出 生", xStart, ypStep);//ypStep += yStep;xpStep = xStart + xStep;//年g2d.drawString("年", xpStep, ypStep);//月xpStep += xStart;g2d.drawString("月", xpStep, ypStep);//日xpStep += xStart;g2d.drawString("日", xpStep, ypStep);//住 址ypStep += yStep;g2d.drawString("住 址", xStart, ypStep);ypStep += idNoSpace;//号码font = new Font("黑体",Font.PLAIN,16);//这里设置颜色有什么用?g2d.setFont(font);g2d.drawString("公民身份号码", xStart, ypStep + 10);//设置头像try {//Image img = ImageIO.read(new File("D:/gen/qie2.png"));Image img = ImageIO.read(new File(".\\qie2.png"));//返回一个 BufferedImage,作为使用 ImageReader(它是从当前已注册 ImageReader 中自动选择的)解码所提供 File 的结果。g2d.drawImage(img, 300,70,null);//  呈现一个图像,在绘制前进行从图像空间到用户空间的转换。} catch (IOException e) {   }return g2d;
//      g2d.dispose();
//
//      try {
//          ImageIO.write(bi, "PNG", new File(outPath));
//      } catch (IOException e) {
//          e.printStackTrace();
//      } finally{
//
//      }  }
}

3\IDCardInfo .java

public class IDCardInfo {private String name = "";private String sex = "";private String nation = "";private String bornYear = "";private String bornMonth = "";private String bornDay = "";private String addr = "";private String idNo = "";private String expDate = "";private String issuingAuthority = "";private String addr1 = "";private String addr2 = "";public String getAddr1() {addr1 = addr.length() > 11 ? addr.substring(0,11) : "";return addr1;}public String getAddr2() {addr2 = addr.length() > 11 ? addr.substring(11) : "";return addr2;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getNation() {return nation;}public void setNation(String nation) {this.nation = nation;}public String getBornYear() {return bornYear;}public void setBornYear(String bornYear) {this.bornYear = bornYear;}public String getBornMonth() {return bornMonth;}public void setBornMonth(String bornMonth) {this.bornMonth = bornMonth;}public String getBornDay() {return bornDay;}public void setBornDay(String bornDay) {this.bornDay = bornDay;}public String getAddr() {return addr;}public void setAddr(String addr) {this.addr = addr;}public String getIdNo() {return idNo;}public void setIdNo(String idNo) {this.idNo = idNo;}public String getExpDate() {return expDate;}public void setExpDate(String expDate) {this.expDate = expDate;}public String getIssuingAuthority() {return issuingAuthority;}public void setIssuingAuthority(String issuingAuthority) {this.issuingAuthority = issuingAuthority;}
}

4\TestGenCard .java

public class TestGenCard {public static void main(String[] args) {IDCardInfo idCard = new IDCardInfo();idCard.setName("赵一");idCard.setSex("男");idCard.setNation("汉");idCard.setBornYear("1999");idCard.setBornMonth("8");idCard.setBornDay("8");idCard.setAddr("陕西省渭南市大荔县黄河镇黄家沟二组");idCard.setIdNo("622426199908080018");try {IDCardGeneratorFront idCardFront = new IDCardGeneratorFront(idCard);idCardFront.paint();System.out.println("complete!!!");} catch (Exception e) {e.printStackTrace();}}
}

转载于:https://my.oschina.net/u/3563297/blog/1805603

IDNO简单生成方法相关推荐

  1. bump map(凹凸贴图)的一个简单生成方法

    用于渲染物体表面,增加真实感的bump map(凹凸贴图)的一个简单生成方法. 1. 在  Perlin Noise Map Generator - OpenProcessing 生成一个perlin ...

  2. java jsp验证码_JSP验证码简单生成方法

    本文实例讲述了JSP验证码简单生成方法.分享给大家供大家参考.具体如下: Color getRandColor(int fc,int bc){//给定范围获得随机颜色 Random random = ...

  3. 一种非常简单的静态网页生成方法介绍

    一.目前的静态页生成方法有简单的模板替换.常见的ASP+FSO等,这里给大家介绍一种更简单的方法.原理就是借助XMLHTTP对象获取目标页面的源代码,然后写入到静态网页文件中.代码如下: Code D ...

  4. php随机分配的方法,PHP生成指定随机字符串的简单实现方法

    搜索热词 本文实例讲述了PHP生成指定随机字符串的简单实现方法.分享给大家供大家参考.具体分析如下: 这是一个简单的函数,没有对生成的内容作强制设定.所以在生成的字符串长度较少的时候,会出现没有指定类 ...

  5. Git简单生成公钥和私钥的方法及git ssh key配置

    Git简单生成公钥和私钥的方法 Git安装完之后,需做最后一步配置.打开git bash,分别执行以下两句命令 git config --global user.name "用户名" ...

  6. python生成10个随机密码_Python简单生成8位随机密码的方法

    本文实例讲述了Python简单生成8位随机密码的方法.分享给大家供大家参考,具体如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import ran ...

  7. Word进行自动生成目录右边页面等格操作简单详细方法

    Word进行自动生成目录右边页面等格操作简单详细方法 Word文档自动生成的目录,但是由于目录的右边不等(见下图),看起来不美观,所以我们可以将目录右边页面进行等格处理. 方法步骤如下: 一.首先选择 ...

  8. 最简单的方法快速生成抖音风格文字——使用HTML和CSS代码

    最简单的方法快速生成抖音风格文字--用HTML和CSS代码 大家好! 这是我第一次与大家分享心得.希望能与大家共同学习.共同提升. 抖音作为近年来大火的APP,其具有特色的图标和字体收到了不少人的喜爱 ...

  9. 一种简单的随机多边形生成方法

    文章目录 搞CNN训练时候有时需要生成一些随机多变形的mask来用用,比如在分类算法中我们有时会随机将图像的一部分区域扣掉或填充为其他内容以模拟遮挡的情况.某些文章中可能会用比较规则的形状,比如矩形或 ...

最新文章

  1. mysql支不支持fulljoin_mysql不支持full join的另一种解决办法 和根据多个表中的相同分组来连接查询...
  2. 基于的BCH的相关应用是不是该降降温?
  3. 算法——海量数据(5%)
  4. 码支付如何对接网站_支付宝当面付门店码如何做?
  5. qfp封装能够linux,QFP、PQFP、LQFP、TQFP封装形式及PCB详解
  6. C++递归斐波那契数列
  7. C++学习之路 | PTA乙级—— 1009 说反话 (20分)(精简)
  8. YOLOv3目标检测有了TensorFlow实现,可用自己的数据来训练
  9. 简单粗暴地理解js原型链--js面向对象编程
  10. HDU 6122 今夕何夕 【数学公式】 (2017百度之星程序设计大赛 - 初赛(A))
  11. android 6.0 ndk版本,[推荐]android-ndk6.0翻译(1)
  12. GBS服装分床裁剪计划软件V4.0正式发布
  13. 社区发现 louvain(fast unfolding)算法
  14. 《C++ Primer 5th》知识点总结练习题解
  15. html5拾色器功能,html5 学习简单的拾色器
  16. 车型代号对照表_上海大众车型与VIN代号对照表
  17. 向前logistic回归与向后筛选出一样的变量_生存分析之Cox回归
  18. 直角三角公式计算机,直角三角函数公式表
  19. 使用Java程序发送邮件|发送有附件的邮件|进行邮件群发
  20. web网站http转成https

热门文章

  1. 关于java中的各种流
  2. Scala swing和FX
  3. 基于springboot实现快递代取管理系统
  4. [转]Linux 进程间通信:共享内存
  5. 使用DBNEWID Utility 修改oracle数据库的 db name 和 dbid
  6. Sql Server 2012 分页方法分析(offset and fetch)
  7. 关于树论【LCA树上倍增算法】
  8. Windows内核执行体对象管理器的操作过程与分析
  9. 远程连接10.81.148.63 HP580
  10. 高速信号传输约翰逊 pdf_在PCB板边走高频高速信号线的注意事项