How do you resize barcode image when saving to a file?


I’m trying to save the barcodes I generate to a file using the LinearBarCode class.

I specificed my desired image DPI.

linearBarCode1.Resolution.DpiX = 300;
linearBarCode1.Resolution.DpiY = 300;

and used the following to save the barcode to an image.


This works fine, but the image saved is too large now. (e.g. 1149 x 213 pixels) If I decrease the dpi settings, the image is smaller, but the quality is significantly decreased and can no longer be scanned using a bar code scanner.



Dear Tony,

Thanks for your post.

You can try to use DpiX=96, DpiY=96, and set the ImageQuality = antialias. It works well to my barcode scaner.


I tried the following, and the generated bar code image can’t be scanned. Attached is the barcode that was generated.

linearBarCode1.Resolution.DpiX = 96;
linearBarCode1.Resolution.DpiY = 96;

linearBarCode1.ImageQuality = (Aspose.BarCode.ImageQualityMode)Enum.Parse(typeof(Aspose.BarCode.ImageQualityMode), “AntiAlias”, true);

If I use the BarCodeControl with dpi=300 and print the aspx page from my web browser, it looks sharp and easily scannable. Is there a bug/limitation with the linearBarCode class?


Dear tonykchan,

The barcode webcontrol render the barcode image from the internal metalfile image of the control.

You can access it with the property metafileImage of the linearBarCode instance. Could you give it another go? I mean use metafileImage in your printing.

And it could be great help to facilitate communicating and trouble-shotting, if you can share some of your code.

Thanks in advance.


I tried using “metafileImage” for saving barcodes to a file, and the barcode generated appears to be sharper, but it’s still not scanable. The barcode generated by BarCodeControl2 scans fine when I print the web page, but linearBarCode1.MetafileImage one doesn’t scan. If you look at the barcodes, they seem slightly different. I’ll try to attach some sample barcodes for review.

Sample Code I am currently using…

BarCodeControl2.SymbologyType = (Aspose.BarCode.Symbology)Enum.Parse(typeof(Aspose.BarCode.Symbology),“Code128”,true);

BarCodeControl2.CaptionAbove.Text = “Purolator Shipment Code”;

BarCodeControl2.CodeText = _shipmentCode;

BarCodeControl2.CodeLocation = (Aspose.BarCode.CodeLocation)Enum.Parse(typeof(Aspose.BarCode.CodeLocation), “Below”, true);

BarCodeControl2.RotationAngle = (Aspose.BarCode.RotationAngle)Enum.Parse(typeof(Aspose.BarCode.RotationAngle), “ZeroDegree”, true);

BarCodeControl2.Resolution.DpiX = 300;

BarCodeControl2.Resolution.DpiY = 300;

BarCodeControl2.ImageQuality = (Aspose.BarCode.ImageQualityMode)Enum.Parse(typeof(Aspose.BarCode.ImageQualityMode), “AntiAlias”, true);

BarCodeControl2.Visible = true;

linearBarCode1 = new Aspose.BarCode.LinearBarCode(_shipmentCode,(Aspose.BarCode.Symbology)Enum.Parse(typeof(Aspose.BarCode.Symbology),“Code39Extended”,true));

linearBarCode1.SymbologyType = (Aspose.BarCode.Symbology)Enum.Parse(typeof(Aspose.BarCode.Symbology),“Code128”,true);

linearBarCode1.CodeText = _shipmentCode;

linearBarCode1.CodeLocation = (Aspose.BarCode.CodeLocation)Enum.Parse(typeof(Aspose.BarCode.CodeLocation), “Below”, true);

linearBarCode1.RotationAngle = (Aspose.BarCode.RotationAngle)Enum.Parse(typeof(Aspose.BarCode.RotationAngle), “ZeroDegree”, true);

linearBarCode1.Resolution.DpiX = 300;

linearBarCode1.Resolution.DpiY = 300;

linearBarCode1.ShowBorder = false;

linearBarCode1.ImageQuality = (Aspose.BarCode.ImageQualityMode)Enum.Parse(typeof(Aspose.BarCode.ImageQualityMode), “AntiAlias”, true);

linearBarCode1.MetafileImage.Save(ConfigurationSettings.AppSettings[“rootPath.barcodes”] + _shipmentCode + “.gif”,System.Drawing.Imaging.ImageFormat.Gif);


sample barcodes…


barcode that isn’t scanable…


Deare Tony,

Try to copy the setting from the web barcode control to the linearbarcode instance,

public void CopyFrom(Aspose.BarCode.Web.UI.BarCodeWebControl webBarCode)
this.linearBarCode.xDimension = webBarCode.xDimension;
this.linearBarCode.BackColor =webBarCode.BackColor;
this.linearBarCode.SymbologyType = webBarCode.SymbologyType;
this.linearBarCode.Width2NarrowRatio = webBarCode.Width2NarrowRatio;
this.linearBarCode.UPCNumberSystem = webBarCode.UPCNumberSystem;
this.linearBarCode.SupplementSpace = webBarCode.SupplementSpace;
this.linearBarCode.SupplementData = webBarCode.SupplementData;
this.linearBarCode.StopSymbolOfCodabar = webBarCode.StopSymbolOfCodabar;
this.linearBarCode.StartSymbolOfCodabar = webBarCode.StartSymbolOfCodabar;
this.linearBarCode.RotationAngle = webBarCode.RotationAngle;
this.linearBarCode.Resolution = webBarCode.Resolution;
this.linearBarCode.BorderDashStyle = webBarCode.BorderDashStyle;
this.linearBarCode.ImageQuality = webBarCode.ImageQuality;
this.linearBarCode.ForeColor = webBarCode.ForeColor;
this.linearBarCode.EnableCheckSum = webBarCode.EnableCheckSum;
this.linearBarCode.EnableEscape = webBarCode.EnableEscape;
this.linearBarCode.CodeText = webBarCode.CodeText;
this.linearBarCode.CodeTextSpace = webBarCode.CodeTextSpace;
this.linearBarCode.CodeLocation = webBarCode.CodeLocation;
this.linearBarCode.CodeColor = webBarCode.CodeColor;
this.linearBarCode.CodeAlignment = webBarCode.CodeAlignment;
this.linearBarCode.Code128CodeSet = webBarCode.Code128CodeSet;
this.linearBarCode.CheckSumVisible =webBarCode.CheckSumVisible;
this.linearBarCode.BarHeight = webBarCode.BarHeight;
this.linearBarCode.CaptionAbove = webBarCode.CaptionAbove;
this.linearBarCode.CaptionBelow = webBarCode.CaptionBelow;
this.linearBarCode.BorderColor = webBarCode.BorderColor;
this.linearBarCode.BorderWidth = webBarCode.ImageBorderWidth;
this.linearBarCode.ImageMargins =webBarCode.ImageMargins;
this.linearBarCode.BorderMargins = webBarCode.BorderMargins;
this.linearBarCode.ShowBorder = webBarCode.ShowBorder;
this.linearBarCode.Font = webBarCode.Font;


Thanks Kyle!

The copying of settings from the WebBarCodeControl -> linearBarCode instance seems to have done the trick.



Dear Tony,

We will add this method in the LinearBarCode class. Therefore, the class will have build-in supporting for copying settings among Web control and WinControl. And the new version will be available as soon as possible.

Thanks again.