I’m trying to use the new generator api instead of the deprecated builder, but the images does not come out the same.
They are similar… but not exactly the same.
Api version 18.11
Code snippet.
public static void main(String[] args) throws Exception {
// Apply a license to avoid the evaluation WaterMark in the BarCode image.
License license = new License();
license.setLicense("Aspose.Total.Java.lic");
final String barcodeValue = "Some text";
BufferedImage img1 = generatebarcodeDeprecated(EncodeTypes.CODE_39_STANDARD, 395.5f, 77f, barcodeValue);
ImageIO.write(img1, "png", new File(EncodeTypes.CODE_39_STANDARD + "_OLD" + ".png"));
BufferedImage img2 = generateBarcodeNew(EncodeTypes.CODE_39_STANDARD,395.5f, 77f, barcodeValue);
ImageIO.write(img2, "png", new File(EncodeTypes.CODE_39_STANDARD + "_NEW" + ".png"));
BufferedImage img3 = generatebarcodeDeprecated(EncodeTypes.QR, 155f, 141f, barcodeValue);
ImageIO.write(img3, "png", new File(EncodeTypes.QR + "_OLD" + ".png"));
BufferedImage img4 = generateBarcodeNew(EncodeTypes.QR, 155f, 141f, barcodeValue);
ImageIO.write(img4, "png", new File(EncodeTypes.QR + "_NEW" + ".png"));
}
@SuppressWarnings("deprecation")
private static BufferedImage generatebarcodeDeprecated(SymbologyEncodeType type, float width, float height, String value) {
BarCodeBuilder builder = new BarCodeBuilder(value, type);
builder.setImageWidth(width);
builder.setImageHeight(height);
return builder.getOnlyBarCodeImage();
}
private static BufferedImage generateBarcodeNew(SymbologyEncodeType type, float width, float height, String value) {
BarCodeGenerator generator = new BarCodeGenerator(type, value);
generator.recalculateValues();
generator.getCodeTextStyle().setLocation(CodeLocation.None);
generator.setAutoSizeMode(AutoSizeMode.NEAREST);
generator.getBarCodeWidth().setMillimeters(width);
generator.getBarCodeHeight().setMillimeters(height);
return generator.generateBarCodeImage();
}