ios-Two-dimensional code generation

Source: Internet
Author: User

1. Create filter Cifilter *filter = [Cifilter filterwithname:@ "Ciqrcodegenerator"];    2. Restore the default [filter SetDefaults];    3. Add QR code to scan out the string nsstring *datastring = @ "This is the QR code sweep out of the string";    NSData *data = [datastring datausingencoding:nsutf8stringencoding];    [Filter Setvalue:data forkeypath:@ "InputMessage"];    4. Obtain the output of the QR code ciimage *outputimage = [Filter outputimage]; 5. The ciimage format of the QR code will be somewhat blurry, so convert ciimage to uiimage and zoom in to show self.imageView.image = [self Createnoninterpolateduiimageformciimage:outputimage withsize:200];** Convert Ciimage to UIImage method **/** * Generates UIImage of the specified size according to Ciimage * * @param image Ciimage * @param size picture width */-(UIImage *) createnoninterpolateduiimageformciimage    :(ciimage *) image withsize: (cgfloat) size{cgrect extent = Cgrectintegral (image.extent);    CGFloat scale = MIN (Size/cgrectgetwidth (extent), size/cgrectgetheight (extent));    1. Create bitmap;    size_t width = cgrectgetwidth (extent) * scale;    size_t height = cgrectgetheight (extent) * scale; Cgcolorspaceref 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);    2. Save bitmap to picture cgimageref Scaledimage = Cgbitmapcontextcreateimage (bitmapref);    Cgcontextrelease (BITMAPREF);    Cgimagerelease (BitmapImage); return [UIImage imagewithcgimage:scaledimage];}

ios-Two-dimensional 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.