iOS self-scanning and two-dimensional code generation

Source: Internet
Author: User

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;&LT;&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

Related Article

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.