Free Support Forum - aspose.com

Problem with BarCodeImage size

Hello, I have problem. I want make barcode image with size 40mm x 18mm, but real size 35mm x 14mm.

//e.Graphics.DpiX = 600

//e.Graphics.DpiY = 600

//width=40

//height=18

private void PrintOnPrinter(PrintPageEventArgs e)
{
Bitmap bitmap = MakeBarcodeImage(code, e.Graphics.DpiX, e.Graphics.DpiY, width, height, vertical);
e.Graphics.PageUnit = System.Drawing.GraphicsUnit.Inch;
e.Graphics.DrawImage(bitmap, ConvertInchToSm.FromMmToInches(left), ConvertInchToSm.FromMmToInches(top));
}

private Bitmap MakeBarcodeImage(string code, float dpiX, float dpiY, float? width, float? height, bool vertical)
{
BarCodeBuilder builder = new BarCodeBuilder(code, Symbology.EAN13);
builder.GraphicsUnit = GraphicsUnit.Inch;
builder.Resolution = new Resolution(dpiX, dpiY, ResolutionMode.Customized);
builder.Margins.Bottom = 0;
builder.Margins.Right = 0;
builder.Margins.Top = 0;
builder.Margins.Left = 0;
builder.BorderVisible = false;
builder.BorderWidth = 0;
if (vertical)
builder.RotationAngleF = 90;
builder.AutoSize = !height.HasValue || !width.HasValue;
if (height.HasValue)
{
builder.ImageHeight = height.Value / 25.4f;
builder.BarHeight = height.Value / 25.4f;
}
if (width.HasValue)
{
builder.xDimension = width.Value / 25.4f / 95f;
builder.ImageWidth = width.Value / 25.4f;
}
return builder.GenerateBarCodeImage();
}

Hi,


Thank you for inquiry.

Could you please update the above program as follows to make it around 30mm x 18mm.

builder.GraphicsUnit = GraphicsUnit.Millimeter;
builder.ImageHeight = height;
builder.BarHeight = height-1;
builder.xDimension = 0.5f;
builder.ImageWidth = width;

The space between bars can be increased by incrementing the value of xDimension, but it crosses the 40mm limit, if I set xDimension to 0.6f. It is not always possible to perfectly generate the image according to the specified size.