Code generated by bar code (code39 code)

Source: Internet
Author: User
Code for generating zryou code (code39 code)

"CoDe 39 bar code Introduction 』

COThe de39 Bar Code represents a total of 43 characters including letters, numbers, and other symbols: A-Z, 0-9,-. $/+ %, space, etc. Its main features are as follows:
◆ The bar code length can be changed.
◆ "*" Is usually used as the start and end operators.
◆ No verification code required
◆CodeDensity: 3-9.4 characters/inch
◆ The blank area is 10 times the narrow area
◆ Used for automatic management of industry, books, and tickets

The third code is a bar code launched by intermec in 1975. It can represent numbers, English letters, hyphens (-), and hyphens (-). ","/"," "," % "," $ "," "(Space), and, "*" is only used as the start and end operators.
It is widely used in various fields because of its simple coding rules, low bit error rate, and many characters. China has also formulated the corresponding national standard (GB12908-91 ).
Three or nine codes have only two unit widths: The width unit and the narrow unit. The width of a unit is one to three times that of a narrow unit. Generally, 2 times, 2.5 times, or 3 times are used for multiple units. Each bar code character with three or nine codes consists of nine units, which have three width units and the rest are narrow units. Therefore, they are called three or nine codes.
Some libraries in China use 39 yards with special verification characters, and the bar code software can print 39 yards suitable for libraries.

Original code: lovlypuppy

There are two classes to implement this function. The first class is drawimagebord. CS.

Using system. drawing;
Using system. Drawing. imaging;
Public abstract class drawimagebord
...{
Protected virtual string bordrulename
...{
Get... {return string. Empty ;}
}

Protected virtual system. Collections. hashtable roles
...{
Get... {return new system. Collections. hashtable ();}
}

String drawstring;
Int width = 800; // The width of the canvas (computable)
Int Height = 36; // 1 CM
Int unitwidth = 1 ;//

Int currentlocation = 0;

Public drawimagebord (string S)
...{
Drawstring = s;
}

Public Virtual void draw (system. Io. stream target)
...{
Bitmap Bm = new Bitmap (width, height );
Graphics G = graphics. fromimage (BM );
G. smoothingmode = system. Drawing. drawing2d. smoothingmode. default;
G. textrenderinghint = system. Drawing. Text. textrenderinghint. antialias;

// Canvas and edge settings
G. Clear (color. White );

G. drawrectangle (pens. White, 0, 0, width, height );
For (INT I = 0; I <drawstring. length; I ++)
...{
This. drawstring (drawstring [I]. tostring (), g );
}
BM. Save (target, imageformat. JPEG );
}
Protected virtual void drawstring (string S, graphics g)
...{
System. Collections. hashtable hash = This. roles;
Object o = hash [s];
If (O = NULL) return;
Char [] chars = O. tostring (). tochararray ();
If (chars. length> 9) return;
Solidbrush blackbrush = new solidbrush (color. Black );
Solidbrush witebrush = new solidbrush (color. White );

For (INT I = 0; I <5; I ++)
...{
// Draw the first 0 black bars
If (chars [I] = '0 ')
...{
Rectangle RE1 = new rectangle (currentlocation, 0, unitwidth, height );
G. fillrectangle (blackbrush, RE1 );
Currentlocation + = unitwidth;
}
Else
...{
Rectangle RE1 = new rectangle (currentlocation, 0, 3 * unitwidth, height );
G. fillrectangle (blackbrush, RE1 );
Currentlocation + = 3 * unitwidth;
}
// Draw 6th white stripes
If (I + 5) <9)
...{
If (chars [I + 5] = '0 ')
...{
Rectangle RE1 = new rectangle (currentlocation, 0, unitwidth, height );
G. fillrectangle (witebrush, RE1 );
Currentlocation + = unitwidth;
}
Else
...{
Rectangle RE1 = new rectangle (currentlocation, 0, 3 * unitwidth, height );
G. fillrectangle (witebrush, RE1 );
Currentlocation + = 3 * unitwidth;
}
}
}
Rectangle re2 = new rectangle (currentlocation, 0, unitwidth, height );
G. fillrectangle (witebrush, re2 );
Currentlocation + = unitwidth;

}
}
Class 2 CODe39drawimagebord. CS inherits drawimagebord. CS

Using system;
Using system. DaTa;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

/** // <Summary>
/// CoDe39drawimagebord abstract description
/// </Summary>
Public class CoDe39drawimagebord: drawimagebord
......{
Private system. Collections. hashtable hash = new system. Collections. hashtable ();
Protected override string bordrulename
......{
Get... {return "CoDe39 ";}
}
Public CoDe39drawimagebord (string S)
: Base (s)
......{

}

Protected override system. Collections. hashtable roles
......{
Get
......{
If (hash. Count> 0) return hash;
Hash. Add ("0", "001100100 ");
Hash. Add ("1", "100010100 ");
Hash. Add ("2", "010010100 ");
Hash. Add ("3", "110000100 ");
Hash. Add ("4", "001010100 ");
Hash. Add ("5", "101000100 ");
Hashing. Add ("6", "011000100 ");
Hash. Add ("7", "000110100 ");

Hash. Add ("8", "100100100 ");
Hash. Add ("9", "010100100 ");
Hash. Add ("A", "100010010 ");
Hash. Add ("B", "010010010 ");
Hash. Add ("C", "110000010 ");
Hash. Add ("ds", "001010010 ");
Hash. Add ("e", "101000010 ");

hash. add ("F", "011000010");
hash. add ("g", "000110010");
hash. add ("H", "100100010");
hash. add ("I", "010100010");
hash. add ("J", "001100010");
hash. add ("k", "100010001");
hash. add ("L", "010010001");

hash. add ("M", "110000001");
hash. add ("N", "001010001");
hash. add ("O", "101000001");
hash. add ("P", "011000001");
hash. add ("Q", "000110001");
hash. add ("r", "100100001");
hash. add ("S", "010100001");

hash. add ("T", "001100001");
hash. add ("u", "100011000");
hash. add ("V", "010011000");
hash. add ("W", "110001000");
hash. add ("X", "001011000");
hash. add ("Y", "101001000");
hash. add ("Z", "011001000");

Hash. Add ("-", "000111000 ");
Hash. Add ("%", "100101000 ");
Hash. Add ("$", "010101000 ");
Hash. Add ("*", "001101000 ");

Return hash;
}
}
}

Call method:

Protected void page_load (Object sender, eventargs E)
...{
CODe39drawimagebord DR = new CODe39drawimagebord ("* 3949178 *");
Dr. Draw (response. outputstream );

}
-- Display result:

-- Display result:

Note:

The generated barcode is not identified by a scanner,
In the future, I will use the symbol ds6608 digital scanner to identify its accuracy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.