Hello everyone,
i am working on barcode generate in C#.net technology i am having CODE 39
here is the code
private Bitmap CreateBarcode(string _data) //_data like “123456”
{
string barcodeData = “" + _data + "”;
Bitmap barcode = new Bitmap(1, 1);
// less than size 40, my barcode reader can not read it.
Font threeOfNine = new Font(“Free 3 of 9”, 40,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
Font arial = new Font(“Arial”, 15,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Pixel);
Graphics graphics = Graphics.FromImage(barcode);
SizeF dataSize = graphics.MeasureString(barcodeData, threeOfNine);
dataSize.Height = 60;
barcode = new Bitmap(barcode, dataSize.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
graphics.DrawString(barcodeData, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.DrawString(_data, arial, new SolidBrush(Color.Black), 50, 40);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();
return barcode;
}
"what changes should i do to make the above code compatible with CODE 128"
Any help will be appreciable
Thank you
Hi shailendra,
Thank you for your inquiry.
Please use the following code snippet to generate the Code128 encoded barcode.
// Generate the barcode
BarCodeBuilder builder = new BarCodeBuilder();
//code text font's type and size
builder.CodeTextFont = new System.Drawing.Font("Verdana", 12f);
//Set the symbology type to Code128
builder.SymbologyType = Symbology.Code128;
//Set the Code text for the barcode
builder.CodeText = "1234567";
//Increase the space between code text and barcode to 1 point
builder.CodeTextSpace = 1.0f;
//Set the Code text for the barcode
builder.CodeText = "1234567";
//Align the code text to center
builder.CodeTextAlignment = System.Drawing.StringAlignment.Center;
//Set the location of the code text to above the barcode
builder.CodeLocation = CodeLocation.Above;
//Set the code text fore color to red
builder.CodeTextColor = System.Drawing.Color.Red;
//Save the image to your system and set its image format to Jpeg
builder.Save("barcode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
BarCodeBuilder builder = new BarCodeBuilder();
//code text font's type and size
builder.CodeTextFont = new System.Drawing.Font("Verdana", 12f);
//Set the symbology type to Code128
builder.SymbologyType = Symbology.Code128;
//Set the Code text for the barcode
builder.CodeText = "1234567";
//Increase the space between code text and barcode to 1 point
builder.CodeTextSpace = 1.0f;
//Set the Code text for the barcode
builder.CodeText = "1234567";
//Align the code text to center
builder.CodeTextAlignment = System.Drawing.StringAlignment.Center;
//Set the location of the code text to above the barcode
builder.CodeLocation = CodeLocation.Above;
//Set the code text fore color to red
builder.CodeTextColor = System.Drawing.Color.Red;
//Save the image to your system and set its image format to Jpeg
builder.Save("barcode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
For details on barcode generation, visit the online documentation:
Thanks for replying
While running this code it is showing following error
"BarCodeBuilder builder = new BarCodeBuilder(); "
The type or namespace name ‘BarCodeBuilder’ could not be found (are you missing a using directive or an assembly reference?)
" builder.SymbologyType = Symbology.Code128; "
The name ‘Symbology’ does not exist in the current context
Thank You
Hi shailendra,
Thank you for writing us back.
Please use the following lines of code to fix the error.
Aspose.BarCode.BarCodeBuilder builder = new Aspose.BarCode.BarCodeBuilder();
builder.SymbologyType = Aspose.BarCode.Symbology.Code128;
Hi Ikram ul Haq,
while running the code it is showing “Aspose” watermark.
how and what is the procedure to remove that watermark.
Thank you
Hi shailendra,
Thank you for your inquiry.
The Aspose watermark is indicating that you are using an evaluation version of the Aspose.BarCode API. The Aspose watermark will be removed when a valid license file will be supplied in the code before accessing any functionality of the API.
Please go through the following URL for details on licensing. This will guide and provide you all information related to licensing.