| Aspose.BarCode for Java provides graphics interface to render barcode on various situations, including awt graphics, web response streams, printers and image. This section demonstrates how to render barcode to printers. In other words, how to print barcode image directly. |
Programming Sample
The following sample shows how to render barcode to printers
[Java]
public class Sample
{
public void paint(Graphics g) {
BarCodeBuilder b = this.getBarCodeBuilder();
//...
bimg = (BufferedImage) b.generateBarCodeImage();
int w = bimg.getWidth();
int h = bimg.getHeight();
int[] rgb = new int[w * h];
bimg.getRGB(0, 0, w, h, rgb, 0, w);
//...
if (rgb.length > 0) {
System.out.println("RGB OK.");
}
g.drawImage(bimg, 0, 0, this);
//this.getBarCodeBuilder().render(g);
}
};
The following sample shows how to render barcode to printers
[Java]
public class Sample { public void paint(Graphics g) { BarCodeBuilder b = this.getBarCodeBuilder(); //... bimg = (BufferedImage) b.generateBarCodeImage(); int w = bimg.getWidth(); int h = bimg.getHeight(); int[] rgb = new int[w * h]; bimg.getRGB(0, 0, w, h, rgb, 0, w); //... if (rgb.length > 0) { System.out.println("RGB OK."); } g.drawImage(bimg, 0, 0, this); //this.getBarCodeBuilder().render(g); } };
Output
Here's the runtime snapshot:
Figure: Rendering barcode to printer graphics
Here's the runtime snapshot:
Figure: Rendering barcode to printer graphics
