We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set barcode image size


I have problems setting image size for my generated barcode image. Here is my code:

BarCodeBuilder barcodeBuilder = new BarCodeBuilder();
barcodeBuilder.CodeLocation = CodeLocation.None;
barcodeBuilder.SymbologyType = Symbology.Code128;
barcodeBuilder.CaptionAbove.Visible = false;
barcodeBuilder.AutoSize = true;
barcodeBuilder.ImageHeight = 12f;
barcodeBuilder.ImageWidth = 25f;

barcodeBuilder.CodeText = “ABCDEF”;
barcodeBuilder.Code128CodeSet = Code128CodeSet.Auto;

Bitmap barcodeBitmapImage = barcodeBuilder.GenerateBarCodeImage();
barcodeBitmapImage.Save( @“D:\test_Auto_full.Jpeg”, ImageFormat.Jpeg );

After save my bitmap image size is not 12 mm x 25 mm (H x W).

I use Aspose.Barcode version, Microsoft .NET Framework 2.0 along with VS 2005 (C# language).


Hi Mindaugas,

Thanks for your post!

If BarCodeBuilder.AutoSize is true, the ImageWidth and ImageHeight will be increased accordingly Default Graphics Unit: Millimeter, so if you want to restrict your bitmap with 12mm*25mm, you should set the AutoSize to be false.


I’ve tried to set AutoSize = False, but it doesn’t help as this property distorts the image - you can’t no longer scan such barcode and it doesn’t look like a proper barcode.


Hi Mindaugas,

Could you please attach the image you got so that I can find how it "distort" it. Thanks!

And If the bars larger than the image, I think you can adapt the BarHeight and xDimension properties to reduce it.


I’ve attached a resulting barcode image - AutoSize set to False, image Width and Height are set as desribed earlier. I’ll attach another barcode image in my second post (no possibility to add more than one attachment in one post) - AutoSize set to True, no manipulations with image Width and Height. Coded text: “ABCDEFGHIJKLMNOPQRSTUVWXYZ”.

I known that you can scale down the image by setting xDimension property, but by setting image Width and Height I expect that generated barcode image will be resized according to specified parameters (maybe xDimension modified accordingly?).


(second attachment - correct barcode image)