android 二维码原理简介

 
把上面的完整序列填充到相应规格的二维码矩阵的区域中
6. 掩摸: 将掩摸图形用于符号的编码区域,使得二维码图形中的深色和浅色(黑色和白色)区域能够比率最优的分布。
    7. 格式和版本信息: 生成格式和版本信息放入相应区域内。
        版本7-40都包含了版本信息,没有版本信息的全为0。二维码上两个位置包含了版本信息,它们是冗余的。
        版本信息共18位,6X3的矩阵,其中6位时数据为,如版本号8,数据位的信息时 001000,后面的12位是纠错位。

练习实现二维码编码与解码过程:(调用 三方包zxing 其中的解码与编码的API)
编码过程:

?
代码片段,双击复制
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
public static void encode(String content, String format, String filePath) {
        try {
                Hashtable hints = new Hashtable(); //设置编码类型
                hints.put(EncodeHintType.CHARACTER_SET, DEFAULT_ENCODING); //编码
                BitMatrix bitMatrix = new QRCodeWriter().encode(content,
                BarcodeFormat.QR_CODE, DEFAULT_IMAGE_WIDTH,
                DEFAULT_IMAGE_HEIGHT,hints);
                 
                //输出到文件,也可以输出到流
                File file = new File(filePath);
                MatrixToImageWriter.writeToFile(bitMatrix, format, file);
                } catch (IOException e) {
                        e.printStackTrace();
                        } catch (WriterException e1) {
                                e1.printStackTrace();
                                }
}



解码过程:    
?
代码片段,双击复制
01
02
03
04
05
06
07
08
BufferedImage image = ImageIO.read(file); //读取文件
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap( new HybridBinarizer(
source));
//解码
Result result = new MultiFormatReader().decode(bitmap);
String resultStr = result.getText();
                System.out.println(resultStr);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值