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