This simple problem has plagued me for nearly two hours, mainly because I did not find a demo in the official document. I can only use the search engine to check the programs written by other programmers, however, it was found that there were pitfalls everywhere. I read four or five examples. None of them were able to run normally, and all of them reported errors. After more than an hour of trying, I finally got it done. Let's just move on to the code.
First, add zxing. dll reference (zxing. dllhttp: // www.jb51.net/dll/zxing.dll.html) to the project)
The second step is to create An aspx file. The code in the background is as follows:
Copy codeThe Code is as follows:
Using ZXing. Common;
Using ZXing;
Using ZXing. Rendering;
Using System. Drawing;
Using System. Drawing. Imaging;
Using ZXing. QrCode. Internal;
Namespace zxingtm
{
Public partial class txm: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
MultiFormatWriter mutiWriter = new MultiFormatWriter ();
BitMatrix bm = mutiWriter. encode ("123456789", BarcodeFormat. CODE_39, 363,150 );
Bitmap img = new BarcodeWriter (). Write (bm );
Img. Save ("d:/1.jpeg", System. Drawing. Imaging. ImageFormat. Jpeg );
}
}
}
In the Code, "123456789" is written to death during testing and can be replaced by variables. BarcodeFormat. CODE_39 and other parameters can be replaced with other parameters to generate bar codes in other formats.
In this case, the barcode image of 1. jepg is output on disk D. The main function has been implemented here. The generated barcode image is as follows:
Scan the barcode with the built-in scanning function of the mobile phone. The result is exactly 123456789.