我:
(1)要看打印机支持什么样的imageType, 我这里是 BufferedImage.TYPE_INT_RGB
/**
* 获取 ean13 条形码图片流
* @param content
* @return
* @throws Exception
*/
public static BufferedImage createBarCode4j(String content,int width,int height) throws Exception{
// 分辨率
int dpi = 2000;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BitmapCanvasProvider provider = new BitmapCanvasProvider(baos, MimeTypes.MIME_PNG, dpi,
BufferedImage.TYPE_INT_RGB, false, 0);
// 生成条形码
EAN13Bean ean13Bean = new EAN13Bean();
ean13Bean.generateBarcode(provider,content);
provider.finish();
baos.close();
return provider.getBufferedImage();
}