BufferedImage bufferedimage1 = new BufferedImage(barcode1.getSize().width, barcode1.getSize().height, 1);
java.awt.Graphics2D graphics2d1 = bufferedimage1.createGraphics();
barcode1.paint(graphics2d1);
JPEGImageEncoder jpegimageencoder = JPEGCodec.createJPEGEncoder(servletoutputstream);
JPEGEncodeParam jpegencodeparam = jpegimageencoder.getDefaultJPEGEncodeParam(bufferedimage1);
jpegencodeparam.setQuality(1.0F, true);
jpegimageencoder.setJPEGEncodeParam(jpegencodeparam);
jpegimageencoder.encode(bufferedimage1, jpegencodeparam);
// 打印
Graphics g =bufferedimage1.createGraphics();
g.drawString("", 0, 0);
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
ImageIO.write(bufferedimage1, "jpg", outstream);
byte[] buf = outstream.toByteArray();
InputStream stream = new ByteArrayInputStream(buf);
PrintService se = PrintServiceLookup.lookupDefaultPrintService();
try {
DocPrintJob job = se.createPrintJob();
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
Doc doc = new SimpleDoc(stream, flavor, null);
job.print(doc, null);
} catch (Exception ex) {
System.out.print(ex.getMessage());
}
------解决方案--------------------
BufferedImage bufferedimage1 = new BufferedImage(barcode1.getSize().width, barcode1.getSize().height, 1);