iOS create QR code

Source: Internet
Author: User

#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

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.