EFQRCode is a library written in Swift for generating and recognizing two-dimensional codes. It is developed based on generating and recognizing two-dimensional codes of the system.
- Generation: Using the input watermarking image/icon and other resources to generate a variety of art two-dimensional codes;
- Recognition: Recognition rate is higher than that of iOS original two-dimensional code.
Project address: https://github.com/EyreFree/EFQRCode
I. Effect Preview
II. Examples
Execute the following commands:
git clone git@github.com:EyreFree/EFQRCode.git; cd EFQRCode/Example; pod install; open EFQRCode.xcworkspace
III. Environment
- XCode 8.0+
- Swift 3.0+
IV. Installation
EFQRCode can be passed through CocoaPods Acquisition. Simply add the following code to your Podfile to implement the introduction:
pod "EFQRCode", '~> 1.2.0'
Quick Use
1. Import EFQRCode
Add the following code to introduce the EFQRCode module where you need to use it:
import EFQRCode
2. Two-Dimensional Code Recognition
Gets the two-dimensional code contained in the picture, which may contain more than one two-dimensional code in the same picture, so the return value is an array of strings:
if let testImage = UIImage(named: "test.png") { if let tryCodes = EFQRCode.recognize(image: testImage) { if tryCodes.count > 0 { print("There are \(tryCodes.count) codes in testImage.") for (index, code) in tryCodes.enumerated() { print("The content of \(index) QR Code is: \(code).") } } else { print("There is no QR Codes in testImage.") } } else { print("Recognize failed, check your input image!") } }
3. Two-dimensional code generation
According to the input parameters, various art two-dimensional code pictures are created, and the quick use method is as follows:
// Common parameters: // Content: Two-dimensional code content // Input Correction Level (Optional): Fault Tolerance Rate // L 7% // M 15% // Q 25% // H 30% (default) // size (Optional): Side Length // magnification (Optional): magnification // (If magnification is not empty, the size parameter will be ignored) // backgroundColor (Optional): Background color // foregroundColor (Optional): Foreground color // icon (Optional): Central Icon // iconSize (Optional): Edge length of central Icon // isIconColorful (Optional): Is the central icon colored? // Optional: Watermarking Graph // watermarkMode (Optional): Watermarking pattern // IsWatermark Colorful (Optional): Is the watermarking image color? // Additional parameters // ForegroundPoint Offset: Foreground point offset // Allow Transparent: Allow transparency
if let tryImage = EFQRCode.generate( content: "https://github.com/EyreFree/EFQRCode", magnification: 9, watermark: UIImage(named: "WWF"), watermarkMode: .scaleAspectFill, isWatermarkColorful: false ) { print("Create QRCode image success!") } else { print("Create QRCode image failed!") }
Result:
VI. Guidelines for Use
Details can be found in the specific use documents: https://github.com/EyreFree/EFQRCode/blob/master/README_CN.md
Notes
- Choose a combination of foreground and background colors with high contrast.
- In order to improve the clarity of generating two-dimensional codes, magnificatio can be used instead of size, or their values can be improved appropriately.
- Excessive magnification/side length/excessive content of two-dimensional code may lead to generation failure.
- It is suggested that the generated two-dimensional codes be tested and put into use. For example, the success of Wechat scanning does not mean that Alipay can also scan successfully. Please do targeted testing according to your specific business needs.
- If you have any questions and look forward to receiving your feedback, Issue and Pul request are welcome.
Note: A star, crab, QAQ can be given if it's easy to use.