Native framework in iOS generates QR code

Source: Internet
Author: User

One or two-dimensional code generation
    • The generation and reading of two-dimensional code has been integrated from iOS7
    • Previously widely used ZBARSDK does not currently support 64-bit processors, in addition to the ZXINGSDK can also generate two-dimensional code
    • Steps to generate a QR code
      • Import Coreimage Framework
      • Generate two-dimensional code with filter Cifilter
    • QR Code content (traditional barcode can only put numbers)
      • Plain text
      • Card
      • URL (can jump to page directly)

The specific code generated by the QR code

1- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event {2     3     //Creating Filters4Cifilter *filter = [Cifilter filterwithname:@"Ciqrcodegenerator"];5     6     //Filter Restore Default7 [Filter setdefaults];8     9     //adding data to a filterTenNSString *string=@"http://www.cnblogs.com/PSSSCode/"; One      A     //Convert nsstring format to nsdata format -NSData *data = [stringdatausingencoding:nsutf8stringencoding Allowlossyconversion:yes]; -      the[Filter Setvalue:data Forkeypath:@"InputMessage"]; -      -     //obtain QR code generated by two-dimensional code filter -Ciimage *image =[Filter outputimage]; +      -     //Add the obtained QR code to the ImageView +Self.imageView.image =[uiimage Imagewithciimage:image];

We can see that the generated QR code is blurred, and the last step of the block is replaced by the method called in the code block below.

1 /**2 * Generate UIImage of the specified size according to Ciimage3  *4 * @param image Ciimage5 * @param size picture width6  */7-(UIImage *) Createnoninterpolateduiimageformciimage: (Ciimage *) Image withsize: (cgfloat) Size8 {9CGRect extent =cgrectintegral (image.extent);TenCGFloat scale = MIN (Size/cgrectgetwidth (extent), size/Cgrectgetheight (extent)); One      A     //1. Create bitmap; -size_t width = cgrectgetwidth (extent) *Scale ; -size_t height = cgrectgetheight (extent) *Scale ; theCgcolorspaceref cs =Cgcolorspacecreatedevicegray (); -Cgcontextref bitmapref = cgbitmapcontextcreate (nil, width, height,8,0, CS, (Cgbitmapinfo) kcgimagealphanone); -Cicontext *context =[Cicontext Contextwithoptions:nil]; -Cgimageref BitmapImage =[Context Createcgimage:image fromrect:extent]; + cgcontextsetinterpolationquality (Bitmapref, kcginterpolationnone); - CGCONTEXTSCALECTM (bitmapref, scale, scale); + Cgcontextdrawimage (Bitmapref, extent, bitmapImage); A      at     //2. Save Bitmap to Picture -Cgimageref Scaledimage =cgbitmapcontextcreateimage (bitmapref); - cgcontextrelease (bitmapref); - cgimagerelease (bitmapImage); -     return[UIImage imagewithcgimage:scaledimage]; -}

Two-dimensional code generated by normal code generated QR code

Native framework in iOS generates QR code

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.