Reputation: 191
I have generated the barcode using barbecue and now I want to resize the barcode as per my need. I tried with BufferedImage and then I got barcode with different size but then I get an additional black line under the barcode.
public class GenerateBarcode { public static void main(String[] args) throws Exception { String initialString = JOptionPane.showInputDialog("Enter the text here"); Barcode barcode = BarcodeFactory.createCode128(initialString); BufferedImage bi = BarcodeImageHandler.getImage(barcode); } }
Here I want to resize "bi".
Upvotes: 1
Views: 5438
Reputation: 1815
Try this code:
Barcode b = BarcodeFactory.create2of7(jTextField1.getText());
b.setBarHeight(5);
b.setBarWidth(1);
Upvotes: 1
Reputation: 1461
To resize any BufferedImage, you can create a new one and draw your old one on top of it with a scaling applied. For example:
double scale = 2;
BufferedImage scaledBi = new BufferedImage((int)(bi.getWidth()*scale), (int) (bi.getHeight()*scale), bi.getType());
Graphics2D g2 = scaledBi.createGraphics();
g2.drawImage(bi, 0, 0, scaledBi.getWidth(), scaledBi.getHeight(), 0, 0, bi.getWidth(), bi.getHeight(), null);
scaledBi
now contains your scaled image. Note that this is not vector based, so I am not sure of the quality. To increase scaling quality, you can play with the rendering hints.
Upvotes: 1