#pragma mark-interpolateduiimage= because the generated QR code is a ciimage, we switch directly to UIImage word size is not good control, so use the following method to return the size of the UIImage
-(UIImage *) Createnoninterpolateduiimageformciimage: (ciimage *) image withsize: (cgfloat ) Size {
CGRect extent = cgrectintegral(image. Extent);
cgfloat Scale = MIN(Size/cgrectgetwidth (extent), size/cgrectgetheight (extent));
//Create a bitmap image that we'll draw into a bitmap context at the desired size;
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);
//Create an image with the contents of our bitmap
cgimageref scaledimage = cgbitmapcontextcreateimage(bitmapref);
//Cleanup
cgcontextrelease(bitmapref);
cgimagerelease(bitmapImage);
return [UIImage imagewithcgimage: scaledimage];
}
#pragma mark-qrcodegenerator-- First is the generation of two-dimensional code, using cifilter is very simple, directly into the generation of two-dimensional code of the string can be
-(ciimage *) createqrforstring: (nsstring *) qrstring {
//need to convert the string to a UTF-8 encoded NSData object
nsdata *stringdata = [qrstring datausingencoding:nsutf8stringencoding];
//Create the filter
cifilter *qrfilter = [cifilter filterwithname:@ "Ciqrcodegenerator"];
//Set the message content and error-correction level
[Qrfilter setValue: StringData forkey:@ "InputMessage"];
[Qrfilter setValue:@ "M" forkey:@ "Inputcorrectionlevel"];
//Send the image back
return qrfilter. Outputimage;
}
————————————————————————
Call:
UIImage *boundimg = [self createnoninterpolateduiimageformciimage: [ Self Createqrforstring:@ "http://baidu.com"] withsize:250.0f];
Birth to a QR code based on a string chain