资源简介
java开发的制作工作证和调用斑马ZXP Series 3C证卡打印机服务。分为两个文件,一个用来生成工作证的正反面,一个是将这个正反面用于打印制卡
代码片段和文件信息
package com.zebra.devdemo.myTest;
import java.awt.*;
import java.io.UnsupportedEncodingException;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class CreateBMP{
public static void main(String[] args) throws IOException {
BufferedImage bufferedImage1=getFront(“resources/front.jpg“);
BufferedImage bufferedImage2=getBack(“D:\\“);
}
private static BufferedImage getFront(String path) {
BufferedImage bimage = null;
try {
//首先需要对图片进行预处理,即修改成指定尺寸
//Thumbnails.of(path).size(1023 639).toFile(“D://a1023x639.jpg“);
ImageIcon imgIcon = new ImageIcon(path);
Image theImg = imgIcon.getImage();
int width = theImg.getWidth(null) == -1 ? 1023 : theImg.getWidth(null);//3250
int height = theImg.getHeight(null) == -1 ? 639 : theImg.getHeight(null);//2040
bimage = new BufferedImage(width height BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimage.createGraphics();
//消除文字锯齿
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASINGRenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//消除画图锯齿
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING RenderingHints.VALUE_ANTIALIAS_ON);
//清除画线锯齿
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROLRenderingHints.VALUE_STROKE_DEFAULT);
g.setColor(Color.white);//背景颜色
g.fillRect(0 0 1023 639);//背景面积及位置width=x.height=y
g.drawImage(theImg 0 0 null);
String fontName=“微软雅黑“;//微软雅黑
g.setColor(Color.black);
g.setFont(new Font(fontName Font.PLAIN 50));
g.drawString(“XXXXXXXXXXXXXXXXX“ 60 90);
//上岗证
g.setColor(Color.black);
g.setFont(new Font(fontName Font.PLAIN 70));
g.drawString(“上岗证“ 750 100); //上岗证
//画直线(上)
g.setStroke(new BasicStroke(4.0f));//线条粗细
g.setColor(Color.black);//线条颜色
g.drawLine(0 120 1023 120);//线条起点及终点位置
//绘制头像
//将图片转换为BufferedImage对象
BufferedImage bImage = ImageIO.read(new File(“D:\\CCCCCCCCCCCC.jpg“));
//graphics.drawImage(bufferedImage.getScaledInstance(imageW imageH Image.SCALE_DEFAULT)100 100 null);
g.drawImage(bImage 64 179 229 275 null);
//姓名
g.setColor(Color.black);
g.setFont(new Font(fontName Font.PLAIN 45));
g.drawString(“姓 名:“ 355 220);
//姓名变量
g.setColor(Color.black);
g.setFont(new Font(fontName Font.PLAIN 45));
g.drawString(“CCCCCCCCCCCC“ 600 220);
//等级
g.setColor(Color.black);
g.setFont(new Font(fontName Font.PLAIN 45));
g.dra
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7847 2020-10-23 14:22 CreateBMP.java
文件 6256 2020-10-23 09:37 ZebraTest2.java
----------- --------- ---------- ----- ----
14103 2
评论
共有 条评论