Now the use of QR code is more and more, then we do the app, sometimes we need to consider the generation and scanning of two-dimensional code
Let's start with a simple two-dimensional code generation
First define a ImageView to display the generated QR code image
It's just a simple thing to do. Convert a string into a two-dimensional code
Import Libqrencode File
Introduction of header File #import "QRCodeGenerator.h" can be used
Imageview.image = [Qrcodegenerator qrimageforstring:@ "Www.cnblogs.com/myselfxiaoxiao" ImageSize: imageview.bounds.size.width];//This is a class method, the first parameter is the string that needs to be converted, and the second parameter is the size of the converted QR code.
Other ways of conversion can be studied on their own.
Mainly about the QR Code scan. Scan function needs to be tested on the real machine
Scan the QR Code section:
Import the Zbarsdk file and introduce the framework
Avfoundation.framework
Coremedia.framework
Corevideo.framework
Quartzcore.framework
Libiconv.dylib
Introduction of header File #import "ZBarSDK.h" can be used
Zbarreaderviewcontroller *reader = [Zbarreaderviewcontroller new]; Read Controller
Reader.readerdelegate = self; Signed agent, when reading to QR code or barcode will go the corresponding method used by the protocol is <ZBarReaderDelegate>
Reader.supportedorientationsmask = Zbarorientationmaskall; Basic adaptation
Zbarimagescanner *scanner = Reader.scanner; QR Code and barcode recognition settings
[Scanner setsymbology:zbar_i25
Config:zbar_cfg_enable
TO:0];
[Self Presentmodalviewcontroller:reader
Animated:yes]; Eject camera
[Reader release];
Next implement the Proxy method
-(void) Imagepickercontroller: (uiimagepickercontroller*) reader
Didfinishpickingmediawithinfo: (nsdictionary*) Info
{
id<nsfastenumeration> results =
[Info objectforkey:zbarreadercontrollerresults];
Zbarsymbol *symbol = nil;
for (symbol in results) {
Break
}
Imageview.image =
[Info objectforkey:uiimagepickercontrolleroriginalimage];
[Reader Dismissmodalviewcontrolleranimated:yes];
NSString *content = Symbol.data;
Next, for the information read to do the corresponding action, such as the URL, open the Web page, and so on.
}
iOS uses ZBARSDK to enable generation and scanning of two-dimensional code