Zbar and zxing are two extremely powerful QR code and barcode recognition tools.

Source: Internet
Author: User

I have done some work on the identification and generation of QR codes. Summary.

Obviously, we will not spend a lot of effort to write this recognition process on our own. This may involve manual identification, so to be lazy, I thought of finding such an open-source tool on the Internet.

Go to their official website and draw the following conclusions:

Zbar can scan the QR code and barcode directly,

Zxing can scan the QR code directly. If you want to scan the QR code, you need to modify it.CodeIt takes some time.

We can also find the source code of zbar and zxing,

It's just that it takes a lot of effort to find the zbar source code, but it can still be found on its official website. After finding it, The zbar Source Code includes the source code on other platforms, such as MAC, Python, etc. The source code is messy and looks a little troublesome. The most important thing is that there are too many links to compile, and the script is run and the library to install. Feel like this library is abroad, it is easy to use, but it is not easy to maintain. So although I have found the zbar open source code, I have never really compiled it completely, so I despise myself. I had to study it in depth. (Note: zbar is not ideal for Chinese, so to fully utilize zbar, you still need to read the source code and compile it .)

Zxing is better, and the source code is provided directly. It is really convenient for a library. Just after I downloaded zxing, I directly used its example to find that the code in this example can only be used for QR code identification, rather than barcode scanning. After researching it, I found it on the Internet. I found that zxing can support simultaneous identification of barcode and QR code, and the code will be pasted later. I personally tried it. It is indeed feasible.

To sum up, zbar is easier to use than zxing, that is, it is more like the difference between a card player and a SLR camera. If you need to modify the code and do something customized, we recommend that you use zxing. If you just want to use it, we recommend that you use zbar.

Okay. Let's talk about how to enable zxing to support bar code scanning.

 
1. In -(Ibaction) Scanpressed :(ID) In the sender method:
 Zxingwidgetcontroller  * Widcontroller = [[  Zxingwidgetcontroller    Alloc  ]  Initwithdelegate  :  Self     Showcancel  :  Yes    Onedmode  :  Yes  ]; 
   Multiformatonedreader  * Onereaders = [[ Multiformatonedreader     Alloc  ]  Init  ];  Qrcodereader * Qrcodereader = [[  Qrcodereader     Alloc  ]  Init  ]; Nsset  * Readers = [[  Nsset  Alloc  ]  Initwithobjects  : Onereaders, qrcodereader, Nil  ];  [Qrcodereader  Release  ];  [Onereaders  Release ]; 

 
2. InZxingwidgetcontroller. M's(Void) captureoutput :( avcaptureoutput *) captureoutput: In the method, comment out the following methods:

If(Onedmode ){


// Let's just give the decoder a vertical band right above the Red Line

Croprect. Origin. x = croprect. Origin. x + (croprect. Size. width/
2)-(One_d_band_height +
1);

Croprect. Size. width = one_d_band_height;


// Do a rotate

Cgimageref croppedimg = cgimagecreatewithimageinrect (capture, croprect );

Capture = [SelfCgimagerotated90: croppedimg];

Capture = [SelfCgimagerotated180: capture];


// Uiimagewritetosavedphotosalbum ([uiimage imagewithcgimage: capture], nil );

Cgimagerel.pdf (croppedimg );

Croprect. Origin. x =
0.0;

Croprect. Origin. Y =
0.0;

Croprect. Size. width = cgimagegetwidth (capture );

Croprect. Size. Height = cgimagegetheight (capture );

}

3. The Code commented out above goes down to about 20 lines of code:

 
Uiimage * scrn = [[uiimage alloc] initwithcgimage: newimage];
 
Changed:
Int backcameraimageorientatiOn = uiimageorientationright; uiimage * scrn = [[uiimage alloc] initwithcgimage: newimage scale: (cgfloat) 1.0 orientation: backcameraimageorientatiOn];

4.Comment out the following code in overlayview. M:

 
Self. onedmode = isonedmodeenabled;

Run the command and you will find that you can scan the QR code and scan the QR code at the same time. This is really convenient.

 
Waiting For more information about portrait mode, refer to the following documents:
Http://groups.google.com/group/zxing/browse_thread/thread/cfe2324e8baf2aaa

 
 Refer:Http://code.google.com/p/zxing/issues/detail? Id = 571

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.