I need create a Bitmap with 1D barcode on it.
Follwing a code excerpt i write.
Code: Select all
Calling code excerpt
private string Encoded_Value = "";
private Barcode1DWriterType Encoded_Type = Barcode1DWriterType.Barcode1DWriterCode39;
private Image _Encoded_Image = null;
private Color _ForeColor = Color.Black;
private Color _BackColor = Color.White;
private int _Width = 400;
private int _Height = 100;
private bool _IncludeLabel = false;
private Font _LabelFont = new Font("Microsoft Sans Serif", 10, System.Drawing.FontStyle.Bold);
private BarcodeAlign _Alignment = BarcodeAlign.BarcodeAlignCenter;
private LabelPositions _LabelPosition = LabelPositions.BOTTOMCENTER;
private RotateFlipType _RotateFlipType = RotateFlipType.RotateNoneFlipNone;
private GdPictureImaging GDImaging = new GdPictureImaging();
private string LicenseNumber = "XXXX";
private string LicenseNumberUpgrade = "YYYY";
private string gdError;
.
.
.
.
Encoded_Value = "0800853012780"; //"BCODE";
Encoded_Type = Barcode1DWriterType.Barcode1DWriterCode39;
IncludeLabel = true;
Alignment = BarcodeAlign.BarcodeAlignCenter;
LabelPosition = LabelPositions.BOTTOMCENTER;
RotateFlipType = RotateFlipType.RotateNoneFlipNone;
topOffset = leftOffset = 0;
//===== Encoding performed here =====
bcw = 2 * leftOffset;
bch = topOffset;
if (IncludeLabel == true)
bch += topOffset;
if (BarcodeDraw(Encoded_Type, EncodeData, IncludeLabel, leftOffset, topOffset, Width - bcw, Height - bch, Color.Black, Alignment, (float)RotateFlipType) == false)
MessageBox.Show(gdError);
// function to draw barcode e return a Bitmap
private bool BarcodeDraw(Barcode1DWriterType bcType, string bcData,bool drawLabel, int left, int top, int width, int height, Color barColor,BarcodeAlign Alignment, float angle)
{
GdPictureStatus GdRet;
GDImaging.SetLicenseNumberUpgrade(LicenseNumber, LicenseNumberUpgrade);
int pImageID = GDImaging.CreateNewGdPictureImage(Width, Height, 24, BackColor);
GdRet = GDImaging.Barcode1DWrite(pImageID, bcType, bcData, left, top, width, height,barColor, Alignment, angle);
gdError = GdRet.ToString();
if (GdRet != GdPictureStatus.OK)
return false;
Bitmap = GDImaging.GetBitmapFromGdPictureImage(pImageID);
if (drawLabel == true)
Add_Label(Bitmap); // Add code string
GDImaging.ReleaseGdPictureImage(pImageID);
// rilascia le risorse allocate da GDPicture
GDImaging.ClearGdPicture();
return true;
}
width = 400, height = 100, top = 0, left = 0
I get expected image (see 400x100.bmp)
If I reduce width to 350 I get a small barcode centered in image (see 350x100.bmp)
Please can you explain logic used to calc width of bars??
Thank you in advance.