从1.5升级到jdk1.6时的条形码生成错误

时间:2014-04-30 11:35:07

标签: java barcode barcode4j

我有一段代码在java 1.5版本中运行,但是当我最近将java版本更新为1.6时,应用程序生成了无法扫描的条形码。

与之前的版本相比,条形码略有不同。 某些线条的厚度也发生了变化

请帮忙

以下代码::

    String str = (String)TSFDataChannel.getValue(httpservletrequest,"BC");

    File file = new File("mybarcode_"+Helpers.stripGarbage(str)+".png");
    OutputStream out = new FileOutputStream(file);

    Barcode barcode;
    try {

        Code128Bean bean = new Code128Bean();

        final int dpi = 500;

        //Configure the barcode generator
        bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
        bean.setFontSize(0); //width exactly one pixel

        bean.doQuietZone(false);
        //bean.setVerticalQuietZone(UnitConv.pt2mm(3)); 
        bean.setHeight(1.5); 
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
        out,"image/png", dpi, BufferedImage.TYPE_BYTE_BINARY, true, 0); 

        //Generate the barcode
        bean.generateBarcode(canvas, str);

        //Signal end of generation
        canvas.finish();

        httpservletresponse.setContentType("APPLICATION/OCTET-STREAM");
        String disHeader = "Attachment;Filename=mybarcode_"+str+".png" ;
        httpservletresponse.setHeader("Content-Disposition", disHeader);

        FileInputStream fileInputStream = new FileInputStream(file);
        int i;
        while ((i=fileInputStream.read())!=-1)
        {
            httpservletresponse.getOutputStream().write(i);
        }

        httpservletresponse.getOutputStream().flush();
        httpservletresponse.getOutputStream().close();
        fileInputStream.close();

    } catch (Exception e1) {
        e1.printStackTrace();
    } finally{
        file.delete();
        out.close();
    }

0 个答案:

没有答案