Expert wanna be
Expert wanna be

Reputation: 10624

Generate barcode with Free 3 of 9 font

public Bitmap CreateBarcode(string data)
{
    data = "55536"; 
    string barcodeData = "*" + data + "*";
    Bitmap barcode = new Bitmap(1, 1);
    Font threeOfNine = new Font("Free 3 of 9 Extended", 31, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

    Font arial = new Font("Arial", 13,
              System.Drawing.FontStyle.Regular,
              System.Drawing.GraphicsUnit.Point);

    Graphics graphics = Graphics.FromImage(barcode);
    SizeF dataSize = graphics.MeasureString(barcodeData, threeOfNine);
    dataSize.Height = 70;

    barcode = new Bitmap(barcode, dataSize.ToSize());
    graphics = Graphics.FromImage(barcode);

    graphics.Clear(Color.White);
    graphics.TextRenderingHint = 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;
}

I generate barcode with the above code, but my scanner can not read the barcode generated (for 55536). BUT if I switch the data value to "1111" or "2222", then the barcode be read very well. so I think it is not a scanner problem, anybody know, what's the wrong with that code? please advice.

Upvotes: 5

Views: 6919

Answers (3)

Pramod Nair
Pramod Nair

Reputation: 1

try to prefix and suffix :

why are you passing the data within the

public Bitmap CreateBarcode(string data)
{
    data="55536"; //dont pass the data from here pass it from outside method for eg. call it   from the        button click or whatever control you are using.
}

Upvotes: -2

civ
civ

Reputation: 1

1.If you're using the supported characters surrounded by the "*" stop and start characters, chances are the problem is either the size of the barcode or the resolution of the printing. 2.Make sure that the size of each character is the same font size. Mixed sizes will not work. 3.When experimenting with changing the color of the bars, remember that darker colors are better. Pastels are not so good. Red is a no-no. Here's a reference for you: asp.net barcode generator using 3 of 9 font.

Upvotes: 0

Doug L.
Doug L.

Reputation: 2716

If you are using only numbers, you could try the 3 of 9 basic font (without the extended). Print the same barcode from Write and compare them to see if your solution is building the complete barcode or if it is getting truncated.

Upvotes: 3

Related Questions