Original address: iOS self-scanning and generating two-dimensional code
1. Two d code generation
Libqrencode Introduction: Is a C language used to parse two-dimensional barcode (QRCode) of the program library, Libqrencode through the phone's CCD camera to scan two-dimensional barcode. Http://pan.baidu.com/s/1eQs1Epk
Import Libqrencode Library, the following direct code:
[OBJC]View plain copy #import <Foundation/Foundation.h> @interface qrcodegenerator:nsobject + (UIImage *) Qrima Geforstring: (NSString *) string imagesize: (cgfloat) size; + (UIImage *) Twodimensioncodeimage: (UIImage *) Twodimensioncode withavatarimage: (UIImage *) avatarimage; @end
[OBJC] View plain copy #import "QRCodeGenerator.h" #import "qrencode.h" enum { qr_margin = 3 }; @implementation QRCodeGenerator + (void) Drawqrcode: (qrcode *) code context: (Cgcontextref) Ctx size: (cgfloat) size { unsigned charchar *data = 0; int width; data = code->data; width = code- >width; float zoom = (Double) size / (code-> Width + 2.0 * qr_margin); cgrect rectdraw = cgrectmake (0, 0, zoom, zoom); // draw cgcontextsetfillcolor (Ctx, cgcolorgetcomponents ([ Uicolor blackcolor]. Cgcolor)); for (int i = 0; i < width; ++i) { for (int j = 0; j &NBSP;<&NBSP;WIDTH;&NBSP;++J) { if (*data & 1) { rectdraw.origin = cgpointmake ((j + Qr_margin) * zoom, (i + qr_margin) * zoom); cgcontextaddrect (Ctx, rectDraw); } &NBSP;&Nbsp; ++data; } } Cgcontextfillpath (CTX); } + (uiimage *) qrimageforstring: (NSString *) String imagesize: (cgfloat) size { if (![ String length]) { return nil; } qrcode *code = qrcode_encodestring ([String utf8string], 0, qr_eclevel_l, qr_mode_ 8, 1