A simple barcode RnD Windows Form application
Follow the steps to run this application :
-
Clone this repo using
git clone https://github.com/sabbiryan/barcode-generator.git
-
Go to
Source\Required Fonts
and install theIDAutomationHC39M.ttf
font on your local machine first. -
Open
Source\Barcode\Barcode.sln
with visual studio (visula studio 2015 suggested). -
Open
GenerateBarcode.cs
for visual design and click onGenerate Button
to view the code. -
Run the application uisng keyborad function F5 or Ctrl + F5 or click on Start.
using (Graphics graphics = Graphics.FromImage(bitmap)) { Font font = new Font("IDAutomationHC39M", 20); PointF point = new PointF(2f, 2f); SolidBrush black = new SolidBrush(Color.Black); SolidBrush white = new SolidBrush(Color.White); graphics.FillRectangle(white, 0, 0, bitmap.Width, bitmap.Height); graphics.DrawString("*"+ barcode + "*", font, black, point); }
Above lines of code actuatlly generate the barcode image.
To save the generated barcode image use bitmap.Save(@"D:/" + DateTime.Now.Ticks + ".png", ImageFormat.Png);
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, ImageFormat.Png);
pictureBox1.Image = bitmap;
pictureBox1.Height = bitmap.Height;
pictureBox1.Width = bitmap.Width;
}
Above lines of code used to display the generated barcode on a PictureBox.