如何为条形码阅读器设置高度和宽度zxing MultiFormatWriter编码功能

时间:2018-06-20 06:10:37

标签: java barcode zxing

当我使用zxing创建条形码时,无法使用移动设备读取条形码。我能够使用https://zxing.org/w/decode.jspx来阅读它。看起来问题在于高度和宽度。这是我的代码

@Test
    public void  create(){
        String data = "Employee Id : 3581834364,Department Id : 13949, Student Id : 35818";
            String format = "jpg";
            ByteArrayOutputStream outParticipant =  new ByteArrayOutputStream();
            int width = 778;
            int height = 60;
            try {
                MultiFormatWriter writer = new MultiFormatWriter();
                BitMatrix matrix = writer.encode(data, BarcodeFormat.CODE_128, width, height);
                System.out.println(matrix.getHeight());
                System.out.println(matrix.getWidth());
                MatrixToImageWriter.writeToStream(matrix, format, outParticipant);
            } catch (WriterException e) {
                e.printStackTrace();
            } catch (IOException e){
                e.printStackTrace();
            }
    }

0 个答案:

没有答案