Last Friday, when wandering around Google code, I checked Google's open-source projects,
Click "Open Source plan" on code.google.com and then click "use Google Code ".
You can view the list of all open-source projects of Google.
After several pages, I found that a zxing has never heard of it before)
It turned out to be a QR code recognition library. Just a few months ago, I was confused about how the anti-counterfeiting code on the train ticket was made (I knew that the code was called qrcode ),
So I downloaded the code. By the way, the sample data in this database is an image, so the size is large, about 130 MB,
I used tortoise SVN. The network speed was too slow and it took three hours,
By the way, I checked relevant information on the Internet and compiled the Java version.
The results are good and can be used. So I compiled the. NET Project, which is a DLL and 212 K of the debug version.
With reference to the guirunner. Java code in javase (a few short sentences of code), a QR code reading and identification (qrcode) is implemented in C)
Refer to matrixtoimagewriter. Java in javase (the code is also short) to generate a QR code image (qrcode)
Paste the code, which is identified:
Using system; <br/> using system. drawing; <br/> using system. windows. forms; <br/> using COM. google. zxing; <br/> using common = com. google. zxing. common; <br/> private void button#click (Object sender, eventargs e) <br/>{< br/> If (this. openfiledialog1.showdialog ()! = Dialogresult. OK) <br/>{< br/> return; <br/>}< br/> image IMG = image. fromfile (this. openfiledialog1.filename); <br/> bitmap bmap; <br/> try <br/>{< br/> bmap = new Bitmap (IMG ); <br/>}< br/> catch (system. io. ioexception IOE) <br/>{< br/> MessageBox. show (IOE. tostring (); <br/> return; <br/>}< br/> If (bmap = NULL) <br/>{< br/> MessageBox. show ("cocould not decode image"); <br/> return; <br/>}< br/> luminancesource source = new rgbluminancesource (bmap, bmap. width, bmap. height); <br/> COM. google. zxing. binarybitmap bitmap = new COM. google. zxing. binarybitmap (new common. hybridbinarizer (source); <br/> result; <br/> try <br/>{< br/> result = new multiformatreader (). decode (Bitmap); <br/>}< br/> catch (readerexception re) <br/>{< br/> MessageBox. show (Re. tostring (); <br/> return; <br/>}</P> <p> MessageBox. show (result. text); <br/>}< br/>
Image Generation Code:
Private void button2_click (Object sender, eventargs e) <br/>{< br/> savefiledialog SFD = new savefiledialog (); <br/> SFD. defaultext = "*. PNG | *. PNG "; <br/> SFD. addextension = true; </P> <p> try <br/> {<br/> If (SFD. showdialog () = dialogresult. OK) <br/>{< br/> string content = "my phone number: 110119112118; phone model: BlackBerry 8100"; <br/> common. bytematrix = new multiformatwriter (). encode (content, B Arcodeformat. qr_code 350,350); <br/> writetofile (bytematrix, system. drawing. imaging. imageformat. PNG, SFD. filename); <br/>}< br/> catch (exception ex) <br/>{< br/> MessageBox. show (ex. message); <br/>}< br/> Public static void writetofile (Common. bytematrix, system. drawing. imaging. imageformat format, string file) <br/>{< br/> bitmap bmap = tobitmap (matrix); <br/> bmap. save (File, format); <br/>}< br/> Public static bitmap tobitmap (Common. bytematrix) <br/>{< br/> int width = matrix. width; <br/> int Height = matrix. height; <br/> bitmap bmap = new Bitmap (width, height, system. drawing. imaging. pixelformat. format32bppargb); <br/> for (INT x = 0; x <width; X ++) <br/>{< br/> for (INT y = 0; Y <peight; y ++) <br/>{< br/> bmap. setpixel (X, Y, matrix. get_renamed (X, Y )! =-1? Colortranslator. fromhtml ("0xff000000"): colortranslator. fromhtml ("0 xffffffff"); <br/>}< br/> return bmap; <br/>}
Source code has two UTF-8 problems, will cause garbled,
1. In the com. Google. zxing. qrcode. encoder. encoder class
Internal const system. String default_byte_mode_encoding = "ISO-8859-1 ";
Here, change ISO-8859-1 to UTF-8
Second: COM. Google. zxing. qrcode. decoder. decodedbitstreamparser class member
Private const system. String utf8 = "utf8 ";
Utf8 should be changed to UTF-8
Mobile phone pixels can be 0.3 million in theory, but automatic focus may be required,
My blackberry 81001.3 million pixels are unrecognizable. There is a rim sample program,
However, the j2's compilation has not been successful, so there is no way to try it. The prompt is that a bunch of symbrs of javax cannot be found (it may be that the wtk2.1 version is a little old)
Generated qrcode diagram:
The information in this image is as follows:
============================================================= ======================================
Sorry, I can't reply to anyone who can leave a message one by one. I put it on GitHub by referring to the code and compiled DLL,
Download https://github.com/F-Sidney/ZXingGUI as needed
References:
Zxing Research
Use zxing to generate a QR code