android模仿疫情健康码的创建

我使用的是android客户端提交数据文件,然后使用zxing生成二维码信息:

步骤一:

客户端基本数据信息:

1:用户姓名

2:身份证号

3:手机号码

4:住址信息

步骤二:

服务端接受到客户端数据之后:

传递参数:

   String  codefor = encode(timeInfor, "", Consts.imgPath, true,reportType);

	/**
	 * 生成二维码(内嵌LOGO)
	 * 
	 * @param content
	 *            内容
	 * @param imgPath
	 *            LOGO地址
	 * @param destPath
	 *            存放目录
	 * @param needCompress
	 *            是否压缩LOGO
	 * @throws Exception
	 */
	public static String encode(String content, String imgPath, String destPath, boolean needCompress,String reportType) throws Exception {
		BufferedImage image = createImage(content, imgPath, needCompress,reportType);
		mkdirs(destPath);
		// String file = new Random().nextInt(99999999) + ".jpg";
		String file = content + ".jpg";
		ImageIO.write(image, FORMAT_NAME, new File(destPath + "/" + file));
		return file;
	}



private static BufferedImage createImage(String content, String imgPath, boolean needCompress,String reportType) throws Exception {
		Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
		hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
		hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
		hints.put(EncodeHintType.MARGIN, 1);
		BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
		int width = bitMatrix.getWidth();
		int height = bitMatrix.getHeight();
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		
		if(reportType.equals("绿码")){
			for (int x = 0; x < width; x++) {
				for (int y = 0; y < height; y++) {
					image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF0cad83 : 0xFFFFFFFF);
				}
			}
		}else if(reportType.equals("黄码")){
			for (int x = 0; x < width; x++) {
				for (int y = 0; y < height; y++) {
					image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFFF5D96E : 0xFFFFFFFF);
				}
			}
		}else if(reportType.equals("红码")){
			for (int x = 0; x < width; x++) {
				for (int y = 0; y < height; y++) {
					image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFFFF0000 : 0xFFFFFFFF);
				}
			}
		}
	
		if (imgPath == null || "".equals(imgPath)) {
			return image;
		}
		// 插入图片
		// QRCodeUtils.insertImage(image, imgPath, needCompress);
		return image;
	}

最后在客户端的显示效果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Android毕业设计源码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值