How to Develop HTML5 projects together [Series 2] And html5 projects together
When I came out of Series 1, everyone was not able to respond positively, and I felt a little lost. In addition, the company had a lot of things at the end of the year, and it had been put aside. Yesterday, we started to continue our research and achieved some progress,
However, we encountered new bottlenecks. Let's share with you the results of the next two days.
Series I determined the idea, mainly starting from the following aspects,
1. Use HTML5 to call the camera and take photos.
2. Upload the image data stream obtained from the photo to the background for resolution.
3. Data is returned. If the resolution fails, the resolution will continue until the resolution is successful.
Step 1 has already been included in my blog.
Http://blog.csdn.net/laijieyao/article/details/41241815
The code for Step 2 is as follows: transmit data to the background through post for parsing.
Function CatchCode () {$ ("# snap "). click (); // do not write for actual use. For Test Generation, click the photo button to obtain the current image. var canvans = document is used for other purposes. getElementById ("canvas"); // obtain the canvas object of the browser page. // the following code starts to compile the data var imgData = canvans. toDataURL (); // convert the image to base64 data var base64Data = imgData. substr (22); // The string after 22 digits is intercepted at the front end as the image data // start asynchronous processing $. post ("uploadImgCode. ashx ", {" img ": base64Data}, function (data, status) {if (status =" success ") {if (data =" OK ") {alert ("OK") ;}else {CatchCode () ;}} else {CatchCode () ;}, "text ");}
The main data stream receiving code in the background:
Img = context. request ["img"]. toString (); // obtain the base64 string byte [] imgBytes = Convert. fromBase64String (img); // converts a base64 string to a byte array System. IO. stream stream = new System. IO. memoryStream (imgBytes); // converts a byte array to a byte stream // transfers the stream back to the Image. This is used to convert a PNG Image into a jpg Image and compress the size for storage. System. Drawing. Image image = System. Drawing. Image. FromStream (stream );
I used the ThoughtWorks. QRCode plug-in from Japan to parse the QR code. I have to blame myself here.
QRCodeDecoder decoder = new QRCodeDecoder(); System.Drawing.Bitmap bitMap=new System.Drawing.Bitmap(path); String decodedString = decoder.decode(new QRCodeBitmapImage(bitMap));
Step 3: If the parsing fails, an exception is reported. If I use return in the catch part, the status at the front end cannot be success, if the status field received by the foreground is not success, the system continues to send data to the background,
Perform recursive calls until the resolution is complete.
Current problems:
If a clear QR code image downloaded from the internet is put into the system, the image can be read successfully. If the QR code captured by the camera cannot be read successfully,
I am also wondering at this point. I initially suspected that the computer camera's pixel was too low, and I still couldn't resolve the problem with my mobile phone scan. Later I checked the information on the Internet and said that I should first make the image black and white, the result still does not work,
Now we are in the bottleneck stage. If you have done this, please give us some guidance so that everyone can learn it. After this bottleneck period expires, I will post all the source code.
Let's give you some comments or ideas !!!!