C# The Wrong (maybe duplicate) Barcode Issued (with BarcodeLib Reference)

1k views Asked by At

Now, I have solved the 1st problem. Thanks to Mihai Ovidiu Drăgoi. But it's still looped.

Newest barcode

Newest code:

        var checkbarcode = (
            from x in db.pelanggan
            where x.barcodepelanggan.Equals(textBox2.Text)
            select x).FirstOrDefault();

        int W = Convert.ToInt32(100);
        int H = Convert.ToInt32(20);
        b.Alignment = BarcodeLib.AlignmentPositions.CENTER;

        BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;

        type = BarcodeLib.TYPE.UPCA;

        b.RotateFlipType = RotateFlipType.RotateNoneFlipNone;

        pictureBox1.BackgroundImage = b.Encode(type, this.textBox2.Text.Trim(), this.btnwarnaBarcode.BackColor, this.btnwarnaLatar.BackColor, W, H);


        pictureBox1.Location = new Point((this.pictureBox1.Location.X + this.pictureBox1.Width / 2) - pictureBox1.Width / 2, (this.pictureBox1.Location.Y + this.pictureBox1.Height / 2) - pictureBox1.Height / 2);

I'm trying to issue my the barcode, and success, but after i scan using the barcode scanner, this barcode is undetected. After i search the problem in the google, the problem is maybe because it looped. I have the comparison of the barcode (which is from different program, here the comparison.

Here is the picture that maybe help you to see the comparison:

The True one (1)- My issued Barcode (The Wrong one) (2)

But after i see the code and compare them, there's not have any different that may causing trouble in my barcode issuing. I use the same barcode type which is, UPC-A.

Here my code:

            var checkbarcode = (
            from x in db.pelanggan
            where x.barcodepelanggan.Equals(textBox2.Text)
            select x).FirstOrDefault();

        int W = Convert.ToInt32(100);
        int H = Convert.ToInt32(20);
        b.Alignment = BarcodeLib.AlignmentPositions.CENTER;

        BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;

        type = BarcodeLib.TYPE.UPCA;

        pictureBox1.BackgroundImage = b.Encode(type, this.textBox2.Text.Trim(), this.btnwarnaLatar.BackColor, this.btnwarnaBarcode.BackColor, W, H);

        pictureBox1.Location = new Point((this.pictureBox1.Location.X + this.pictureBox1.Width / 2) - pictureBox1.Width / 2, (this.pictureBox1.Location.Y + this.pictureBox1.Height / 2) - pictureBox1.Height / 2);

The idea is, when the txtbarcode changed, the barcode is printed on the picture box at the right side or user's card group box.

Any help from you may help me to scan the barcode without it being looped. Thanks in advance :D

The true code as the reference: www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library

1

There are 1 answers

15
Mihai Ovidiu Drăgoi On BEST ANSWER

Heh, found it - the colors are inverted. If you download the second image and invert colors, any scanner will read the correct value. Check your code and make sure you aren't inverting colors anywhere.

Or, maybe it's easier - simply invert them again before displaying them.

PS - you probably just need to switch this.btnwarnaLatar.BackColor and this.btnwarnaBarcode.BackColor in your b.Encode()