#import "LCTwoCodeImage.h"
@implementation lctwocodeimage
+ (UIImage *) Gotocreatmytwocode:(nsstring *) string {
// Create a QR code initial layer rendering by passing in the string
ciimage * firstimage = [self creatciimagefromstring: string];
// ciimage to generate two-dimensional code
UIImage * QRCode = [self createnoninterpolateduiimageformciimage: Firstimage Withsize:250.0f];
return qrcode;
}
+ (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];
}
+ (ciimage *) creatciimagefromstring: (nsstring *) string {
nsdata * stringdata = [string datausingencoding:nsutf8stringencoding];
// add layer
cifilter * Qrfiler = [cifilter filterwithname:@ "Ciqrcodegenerator"];
[Qrfiler setValue: StringData forkey:@ "InputMessage"];
[Qrfiler setValue:@ "M" forkey:@ "Inputcorrectionlevel"];
return [Qrfiler outputimage];
}
@end
iOS create QR code