iOS development-two-D code generation

Source: Internet
Author: User

I. Need to include header files

#import <CoreImage/CoreImage.h>

Two. Sample code--The following generated QR code is not clear enough:

1- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{2     3     //0. Import header file #import <CoreImage/CoreImage.h>4     5     //1. Create a filter-Apple does not encapsulate this character as a constant6Cifilter *filter = [Cifilter filterwithname:@"Ciqrcodegenerator"];7     8     //2. Filter restore default Settings9 [Filter setdefaults];Ten      One     //3. Add data to the filter (regular expression/account number and password)--set filter by KVC, only set NSData type ANSString *datastring =@"http://www.baidu.com"; -NSData *data =[datastring datausingencoding:nsutf8stringencoding]; -[Filter Setvalue:data Forkeypath:@"InputMessage"]; the      -     //4. Get the output of the QR code -Ciimage *outputimage =[Filter outputimage]; -      +     //5. Display two-dimensional code -Self.imageView.image =[UIImage imagewithciimage:outputimage]; +}

Three. Call the following method can generate a clear QR code image, when used can also be added to the UIImage a classification. There are no categories to extract.:

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]; -}

iOS development-two-D code generation

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.