我有一段代码在 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();
}