How To Write C# Code For Barcode Code 128? S’abonner

0
Avatar
Legacy Poster

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 :) 

1 commentaires

0
Avatar
Ian Cummings
Modérateur
Actions pour les commentaires Permalien

I might be biased, but I suggest you use BarTender via .NET automation instead of trying to do this yourself.

Vous devez vous connecter pour laisser un commentaire.