Barcode image size

Hello Team, we are using Aspose-barcode-21.12.jar in our code with purchased license.
Due to JAR version upgradation, we forced changed our old Java code and due to new code changes, we can see barcode image size is enlarged, below is code.
Please advise on same,

BarcodeGenerator bg= new BarcodeGenerator(EncodeTypes.CODE_39_EXTENDED);
bg.setCodeText(“ABC”);
bg.getParameters().getImageHeight().setMillimeters(70.0f);
bg.getParameters().getBarcode().getBarHeight().setMillimeters(50.0f);
bg.getParameters().getBorder().setVisible(false);
bg.getParameters().getBarcode().getXDimension().setMillimeters(2.0f);
bg.getParameters().getBarcode().setChecksumEnabled(EnableChecksum.NO);
bg.getParameters().setResolution(300);
bg.save(strBCdImgPath,BarCodeImageFormat.JPEG);

@TIK,

Please add a line to your code segment after you specify code text:

bg.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);

Also, see the document with examples on barcode image sizing modes and their effects for your reference.

Thanks Amjad, for quick reply!

We can see changes in Image dimensions and less in size but barcode image still vertically stretched. Below is code.
bg.setCodeText(bcodeType);
bg.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);
bg.getParameters().getImageHeight().setMillimeters(70.0f);
bg.getParameters().getBarcode().getBarHeight().setMillimeters(50.0f);
bg.getParameters().getBorder().setVisible(false);
bg.getParameters().getBarcode().getXDimension().setMillimeters(2.0f);
bg.getParameters().getBarcode().setChecksumEnabled(EnableChecksum.NO);
bg.getParameters().setResolution(300);
bg.save(strBCdImgPath,BarCodeImageFormat.JPEG);

@TIK,

Please don’t set resolution to get proper image size, so you may remove or comment the following line of code:

bg.getParameters().setResolution(300);