QR code 快速响应码 二维码

小编最近突发奇想,想学一学二维码方面的知识,错漏之处该是很多的,希望大家多多包含:

先来看看国内现在使用最多一种二维码:QR 码(快速响应码),通过查看资料得知它流行的最主要原因就是它速度快,并且支持汉字,对于我们这个汉字文化大国,如果一项产品不支持汉字,那肯定是活不长久的。

下面是其功能图:


QR code的编码规则因数据类型的不同而不同,其编码模式有扩展解释模式(ECI)、数字模式(NC)、字母数字模式(AC)、8位字节模式(主要针对拉丁和假名)、中国汉字模式。

在编码时将数据转化为二进制位流序列,再进行纠错,然后按照每八位一个码字,将位流序列转为码字序列并在矩阵中布置模块进行掩膜处理,构成最终的数据符号。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring Boot中生成二维码,你可以使用ZXing库。ZXing是一个开放源码的条形码和二维码生成库,它支持多种编程语言,包括Java。 首先,你需要在你的项目中添加ZXing依赖。你可以在Maven中添加以下依赖: ```xml <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.4.1</version> </dependency> ``` 然后,你可以使用以下代码在Spring Boot中生成二维码: ```java import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import javax.imageio.ImageIO; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; @RestController public class QRCodeController { @GetMapping(value = "/qrcode/{text}", produces = MediaType.IMAGE_PNG_VALUE) public ResponseEntity<BufferedImage> generateQRCode(@PathVariable String text) throws WriterException { int width = 300; int height = 300; QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ImageIO.write(bufferedImage, "png", baos); } catch (Exception e) { e.printStackTrace(); } return ResponseEntity.ok().body(bufferedImage); } } ``` 在上面的代码中,我们使用QRCodeWriter类生成二维码,然后将其转换为BufferedImage并返回给客户端。请注意,我们还设置了响应的MediaType为“image/png”。 你可以通过以下URL在浏览器中访问该REST API生成二维码: ``` http://localhost:8080/qrcode/your-text-here ``` 你可以将“your-text-here”替换为你要生成二维码的文本。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值