Two-dimensional code generated in "Swift" iOS

Source: Internet
Author: User
Tags set background

In iOS development, you can generate QR codes for your own code, and you need to use a framework Coreimage

Coreimage frame can make filters, GIF motion diagram, QR code, etc.

Look first.

The following code is directly attached (OC is the same process as below)

1 func Createqrcode () {2     3         //Create a filter4Let Qrfilter = Cifilter (name:"Ciqrcodegenerator")5         //Reset the initial value of the filter6 qrfilter.setdefaults ()7         //set the contents of the filter via KVC (you need to convert the string into binary data)8Qrfilter.setvalue ("I'm a QR code .". datausingencoding (nsutf8stringencoding, Allowlossyconversion:true), Forkey:"InputMessage")9         //output Image (note that the resulting QR code size is about 23*23, not clear)TenLet Ciimage =Qrfilter.outputimage One          A          -         //further processing, using another filter--monochrome, deformation filter -Let Colorfilter = Cifilter (name:"Cifalsecolor") the         //Reset the initial value of the filter - colorfilter.setdefaults () -         //start processing unclear pictures -Colorfilter.setvalue (Ciimage, Forkey:"Inputimage") +         //Set foreground color (note only with Cicolor, use Uicolor will collapse) -Colorfilter.setvalue (Cicolor (red:0, Green:0, Blue:0), Forkey:"InputColor0") +         //Set Background color AColorfilter.setvalue (Cicolor (red:1, Green:1, Blue:1), Forkey:"InputColor1") at         //enlarge picture, enlarge five times times -Let transform = Cgaffinetransformmakescale (5,5) -         //Zoom in -Let Transformiamge =colorFilter.outputImage.imageByApplyingTransform (Transform) -          -          in         //take a picture with a imageview to try the effect ha (note to turn Ciimage into UIImage) -Qrcodeview.image =UIImage (CIIMAGE:TRANSFORMIAMGE) to  +}

The execution of this code is the picture shown above ~

Two-dimensional code generated in "Swift" iOS

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.