private void button1_Click(object sender, EventArgs e)
{
BuildBarcode();
}
void BuildBarcode()
{
System.Drawing.Image image;
int width = 200, height = 100;
byte[] buffer = GetBarcode(height, width, BarcodeLib.TYPE.CODE128, textBox1.Text, out image);
try
{
// pictureBox1.Image.Save(@"C:\aa.bmp");
image.Save(@"C:\aa.bmp");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
byte[] GetBarcode(int height, int width, BarcodeLib.TYPE type,
string code, out System.Drawing.Image image)
{
image = null;
BarcodeLib.Barcode b = new BarcodeLib.Barcode();
b.BackColor = System.Drawing.Color.White;
b.ForeColor = System.Drawing.Color.Black;
b.IncludeLabel = true;
b.Width = 50;
b.Height = 25;
b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);
b.LabelFont = font;
b.Height = height;
b.Width = width;
image = b.Encode(type, code);
SaveImage(image, Guid.NewGuid().ToString("N") + ".png");
byte[] buffer = b.GetImageData(BarcodeLib.SaveTypes.PNG);
return buffer;
}
void SaveImage(Image img, string name)
{
pictureBox1.Image = img;
}