C# Barcode 39

To create a Code39 barcode using C# or any .net language first go to http://code.google.com/p/zxing/ and download the C# library and build it. Direct link for version 2 source (http://code.google.com/p/zxing/downloads/detail?name=ZXing-2.0.zip&can=2&q=)

Add the zxing.dll file as a reference to your project.

        using System.Drawing;
        Bitmap bmp = BarCode39("Message");

        public Bitmap BarCode39(string codeMessage)
        {
            com.google.zxing.oned.Code39Writer writer = new com.google.zxing.oned.Code39Writer();
            com.google.zxing.common.ByteMatrix matrix;

            int width = 180;
            int height = 120;
            matrix = writer.encode(codeMessage, com.google.zxing.BarcodeFormat.CODE_39, 
                width, height, null);


            Bitmap img = new Bitmap(width, height);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = img.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        img.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        img.SetPixel(x, y, Color.Black);
                    }
                }
            }


            return img;

        }

       }