iOS development--Generate barcodes, QR codes

Source: Internet
Author: User

-(void) Viewdidload {

[Super Viewdidload];

Self.imageView.image = [Self generatebarcode:@ "1524829417" width:60 height:60];

Self.imageView2.image = [Self generateqrcode:@ "1524829417" width:60 height:60];

}

-(UIImage *) Generateqrcode: (NSString *) code width: (cgfloat) Width height: (cgfloat) Height {

Generate Barcode Pictures

Ciimage *qrcodeimage;

NSData *data = [code datausingencoding:nsisolatin1stringencoding Allowlossyconversion:false];

Cifilter *filter = [Cifilter filterwithname:@ "Ciqrcodegenerator"];

[Filter Setvalue:data forkey:@ "InputMessage"];

[Filter setvalue:@ "H" forkey:@ "Inputcorrectionlevel"];

Qrcodeimage = [Filter outputimage];

Eliminate Blur

CGFloat ScaleX = width/qrcodeimage.extent.size.width; Extent returns the frame of the picture

CGFloat ScaleY = height/qrcodeimage.extent.size.height;

Ciimage *transformedimage = [Qrcodeimage Imagebyapplyingtransform:cgaffinetransformscale (CGAffineTransformIdentity , ScaleX, ScaleY)];

return [UIImage Imagewithciimage:transformedimage];

}

-(UIImage *) Generatebarcode: (NSString *) code width: (cgfloat) Width height: (cgfloat) Height {

Generate two-dimensional code images

Ciimage *barcodeimage;

NSData *data = [code datausingencoding:nsisolatin1stringencoding Allowlossyconversion:false];

Cifilter *filter = [Cifilter filterwithname:@ "Cicode128barcodegenerator"];

[Filter Setvalue:data forkey:@ "InputMessage"];

Barcodeimage = [Filter outputimage];

Eliminate Blur

CGFloat ScaleX = width/barcodeimage.extent.size.width; Extent returns the frame of the picture

CGFloat ScaleY = height/barcodeimage.extent.size.height;

Ciimage *transformedimage = [Barcodeimage Imagebyapplyingtransform:cgaffinetransformscale ( Cgaffinetransformidentity, ScaleX, ScaleY)];

return [UIImage Imagewithciimage:transformedimage];

}

iOS development--Generate barcodes, QR codes

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.