当前位置: 首页 > 编程日记 > 正文

EFQRCode:自动生成花式二维码

原文链接:https://github.com/EyreFree/EFQRCode
EFQRCode:自动生成花式二维码。# 为开源点赞# —— 由SwiftLanguage分享

EFQRCode is a tool to generate QRCode UIImage or recognize QRCode from UIImage, in Swift. It is based on CIDetector and CIFilter.

  • Generation: Create pretty two-dimensional code image with input watermark or icon;
  • Recognition: Recognition rate is higher than simply CIDetector.

中文介绍

Overview

Demo

To run the example project, clone the repo, and run pod install from the Example directory first.

Or you can run the following command in terminal:

git clone git@github.com:EyreFree/EFQRCode.git; cd EFQRCode/Example; pod install; open EFQRCode.xcworkspace

Requirements

  • XCode 8.0+
  • Swift 3.0+

Installation

CocoaPods

EFQRCode is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "EFQRCode", '~> 1.2.0'

Usage

1. Import EFQRCode

Import EFQRCode module where you want to use it:

import EFQRCode

2. Recognition

Get QR Codes from UIImage, maybe there are several codes in a image, so it will return an array:

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. Generation

Create QR Code image, quick usage:

// Common parameters:
//                         content: Content of QR Code
// inputCorrectionLevel (Optional): error-tolerant rate
//                                  L 7%
//                                  M 15%
//                                  Q 25%
//                                  H 30%(Default)
//                 size (Optional): Width and height of image
//        magnification (Optional): Magnification of QRCode compare with the minimum size
//                                  (Parameter size will be ignored if magnification is not nil)
//      backgroundColor (Optional): Background color of QRCode
//      foregroundColor (Optional): Foreground color of QRCode
//                 icon (Optional): Icon in the middle of QR Code Image
//             iconSize (Optional): Width and height of icon
//       isIconColorful (Optional): Is icon colorful
//            watermark (Optional): Watermark background image
//        watermarkMode (Optional): Watermark background image mode, like UIViewContentMode
//  isWatermarkColorful (Optional): Is Watermark colorful// Extra parameters:
//           foregroundPointOffset: Offset of foreground point
//                allowTransparent: Allow transparent
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:

User Guide

1. Recognition

EFQRCode.recognize(image: UIImage)

Or

EFQRCodeRecognizer(image: image).contents

Two way before is exactly the same, because of the possibility of more than one two-dimensional code in the same iamge, so the return value is `[String]? ', if the return is nil means that the input data is incorrect or null. If the return array is empty, it means we can not recognize any two-dimensional code at the image.

2. Generation

EFQRCode.generate(content: String, inputCorrectionLevel: EFInputCorrectionLevel, size: CGFloat, magnification: UInt?, backgroundColor: UIColor, foregroundColor: UIColor, icon: UIImage?, iconSize: CGFloat?, isIconColorful: Bool, watermark: UIImage?, watermarkMode: EFWatermarkMode, isWatermarkColorful: Bool
)

Or

EFQRCodeGenerator(content: content,inputCorrectionLevel: inputCorrectionLevel,size: size,magnification: magnification,backgroundColor: backgroundColor,foregroundColor: foregroundColor,icon: icon,iconSize: iconSize,isIconColorful: isIconColorful,watermark: watermark,watermarkMode: watermarkMode,isWatermarkColorful: isWatermarkColorful
).image

Two way before is exactly the same, the return value is UIImage?, if the return is nil means that there is some wrong during the generation.

If you want to use the extra parameters, you must establish a EFQRCodeGenerator object:

let generator = EFQRCodeGenerator(content: content,inputCorrectionLevel: inputCorrectionLevel,size: size,magnification: magnification,backgroundColor: backColor,foregroundColor: frontColor,icon: icon,iconSize: iconSize,isIconColorful: iconColorful,watermark: watermark,watermarkMode: watermarkMode,isWatermarkColorful: watermarkColorful
)
generator.foregroundPointOffset = self.foregroundPointOffset
generator.allowTransparent = self.allowTransparent// Final two-dimensional code image
generator.image

Parameters explaination:

  • content: String?

Content, compulsive, capacity is limited, 1273 character most, the density of the two-dimensional lattice increases with the increase of the content. Comparison of different capacity is as follows:

10 characters250 characters
  • inputCorrectionLevel: EFInputCorrectionLevel

Error-tolerant rate, optional, 4 different level, L: 7% / M 15% / Q 25% / H 30%, default is H, the definition of EFInputCorrectionLevel:

// EFInputCorrectionLevel
public enum EFInputCorrectionLevel: Int {case l = 0;     // L 7%case m = 1;     // M 15%case q = 2;     // Q 25%case h = 3;     // H 30%
}

Comparison of different inputCorrectionLevel:

LMQH
  • size: CGFloat

Two-dimensional code length, optional, default is 256 (PS: if magnification is not nil, size will be ignored).

  • magnification: UInt?

Magnification, optional, default is nil.

Because in accordance with the existence of size scaling two-dimensional code clarity is not high, if you want to get a more clear two-dimensional code, you can use magnification to set the size of the final generation of two-dimensional code. Here is the smallest ratio relative to the two-dimensional code matrix is concerned, if there is a want size but I hope to have a clear and size and have size approximation of the two-dimensional code by using magnification, through maxMagnificationLessThanOrEqualTo (size: CGFloat), andminMagnificationGreaterThanOrEqualTo (size: CGFloat), want to get magnification these two functions the specific value, the use of specific methods are as follows:

let generator = EFQRCodeGenerator(content: content,inputCorrectionLevel: inputCorrectionLevel,size: size,magnification: magnification,backgroundColor: backColor,foregroundColor: frontColor,icon: icon,iconSize: iconSize,isIconColorful: iconColorful,watermark: watermark,watermarkMode: watermarkMode,isWatermarkColorful: watermarkColorful
)// Want to get max magnification when size is less than or equalTo 600
generator.magnification = generator.maxMagnificationLessThanOrEqualTo(size: 600)// Or// Want to get min magnification when size is greater than or equalTo 600
// generator.magnification = generator.minMagnificationGreaterThanOrEqualTo(size: 600)// Final two-dimensional code image
generator.image
size 300magnification 9
  • backgroundColor: UIColor

BackgroundColor, optional, default is white.

  • foregroundColor: UIColor

ForegroundColor, optional, color of code point, default is black.

ForegroundColor set to redBackgroundColor set to gray
  • icon: UIImage?

Icon image in the center of code image, optional, default is nil.

  • iconSize: CGFloat?

Size of icon image, optional, default is 20% of size:

Default 20% sizeSet to 64
  • isIconColorful: Bool

Is icon colorful, optional, default is true.

  • watermark: UIImage?

Watermark image, optional, default is nil, for example:

12
  • watermarkMode: EFWatermarkMode

The watermark placed in two-dimensional code position, optional, default is scaleAspectFill, refer to UIViewContentMode, you can treat the two-dimensional code as UIImageView, the definition of UIViewContentMode:

// Like UIViewContentMode
public enum EFWatermarkMode: Int {case scaleToFill        = 0;case scaleAspectFit     = 1;case scaleAspectFill    = 2;case center             = 3;case top                = 4;case bottom             = 5;case left               = 6;case right              = 7;case topLeft            = 8;case topRight           = 9;case bottomLeft         = 10;case bottomRight        = 11;
}
  • isWatermarkColorful: Bool

Is watermark colorful, optional, default is true.

  • foregroundPointOffset: CGFloat

Foreground point offset, optional, default is 0, is not recommended to use, may make the two-dimensional code broken:

00.5
  • allowTransparent: Bool

Allow watermark image transparent, optional, default is true:

truefalse

PS

  1. Please select a high contrast foreground and background color combinations;
  2. You should use magnification instead of size if you want to improve the definition of QRCode image, you can also increase the value of them;
  3. Magnification too high/Size too long/Content too much may cause failure;
  4. It is recommended to test the QRCode image before put it into use;
  5. You can contact me if there is any problem, both Issue and Pull requestare welcome.

PS of PS: I wish you can click the Star button if this tool is useful for you, thanks, QAQ...

Author

EyreFree, eyrefree@eyrefree.org

License

EFQRCode is available under the MIT license. See the LICENSE file for more info.

相关文章:

centos删除系统自带的httpd

centos删除系统自带的httpd 1、[rootlocalhost etc]# rpm -qa|grep httpd,查看与httpd相关软件包。 httpd-tools-2.2.15-15.el6.centos.i686 httpd-2.2.15-15.el6.centos.i686 www.2cto.com 2、然后删除httpd: [rootlocalhost etc]# rpm -e httpd 出现问…

[C#]ASP.NET MVC 3 在线学习资料

最近在研究如何把Twitter Bootstrap移植到ASP.NET MVC 3上,攒了点资料,先贴在之里,以后整理了写心得。 1. http://www.codeproject.com/Articles/404633/Transform-ASP-NET-MVC3-Default-Template-with-Twitt 这是一篇介绍如何把默认的ASP.NE…

域渗透提权之MS14-068

0x00 前言 在做渗透测试时,当遇到域环境,获取到一个域成员账号后,如果域控制器未打好补丁,则可以利用本文所提到的漏洞,快速获取到域控制器权限。笔者这里总结网上已有资料,加以描述,希望你能在…

iOS 高可控性日历基础组件 - SKCalendarView 的使用和实现思路的分享

阅读 61收藏 52017-04-02原文链接:http://www.jianshu.com/p/ce4c64a4d437SKCalendarView 是一个高可控性的日历基础组件,为了提高应用的自由度,默认只提供了日历部分的视图封装,但不涵盖切换月份按钮、年月分显示等非关键性控件&…

懒加载 字典转模型 自定义cell

1 懒加载: 1> 什么是懒加载? 懒加载又称为延时加载,即在系统调用的时候加载,如果系统不调用则不会加载.所谓的懒加载其实就是重写其 get 方法. 2> 特点:在使用懒加载的时候要先判断该方法是否已经存在,如果不存在则再进行实例化. 3> 优点: 不必将创建对象的方法都…

SQL GROUP BY 语句

合计函数 (比如 SUM) 常常需要添加 GROUP BY 语句。 GROUP BY 语句 GROUP BY 语句用于结合合计函数,根据一个或多个列对结果集进行分组。 SQL GROUP BY 语法 SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator valu…

docker如何push镜像到docker hub个人的仓库

docker如何push镜像到docker hub个人的仓库 step1——找到本地镜像的ID&#xff1a;docker imagesstep2——登陆Hub&#xff1a;docker login --usernameusername --passwordpassword --emailemailstep3——tag&#xff1a;docker tag <imageID> <namespace>/<…

博客开通第一天,加油

博客开通第一天&#xff0c;加油转载于:https://www.cnblogs.com/tianyang01/p/5499881.html

【iOS 开发】iOS 10.3 如何更换 app 图标

2017-04-06 KyrieXu Cocoa开发者社区iOS 10.3 开放了更换 app 图标的 API&#xff0c;核心方法是下面这个&#xff1a; func setAlternateIconName(_ alternateIconName: String?, completionHandler: ((Error?) -> Void)? nil) 这是官方文档&#xff0c;但是你还需要在…

WordPress qTranslate插件跨站请求伪造漏洞

漏洞名称&#xff1a;WordPress qTranslate插件跨站请求伪造漏洞CNNVD编号&#xff1a;CNNVD-201306-058发布时间&#xff1a;2013-06-07更新时间&#xff1a;2013-06-07危害等级&#xff1a; 漏洞类型&#xff1a;跨站请求伪造威胁类型&#xff1a;远程CVE编号&#xff1a;CV…

ESXi6.5环境搭建(一:VMware Workstations 12 Pro 环境的安装及配置)

实验目的及要求 完成VMware workstations安装&#xff0c;会应用相关操作&#xff1b;完成虚拟机中ESXI6.5平台的安装及网络环境配置&#xff1b;完成VMware vSphere Client 6.0软件在PC端的安装及配置&#xff1b;完成使用浏览器或者VMware vSphere Client 6.0中对ESXI6.5的操…

[vs2008]Visual Studio 2008 SP1添加或删除功能提示查找SQLSysClrTypes.msi文件

前言 今天接到领导布置的一个任务&#xff0c;是之前同事负责的项目。离职了&#xff0c;现在客户有些地方需要修改&#xff0c;由于我之前参与过&#xff0c;就落在我的头上了。 然后我就把代码弄了过来&#xff0c;打开发现其中需要用到水晶报表。&#xff08;我觉得不好用&a…

iOS10.3 的评论系统

作者 xuyafei86 关注 2017.03.30 12:39* 字数 428 阅读 265评论 4喜欢 11iOS10.3 对 App 的评论系统进行了较大的升级。主要在三个方面。 支持 App 内评分 在此之前我们要实现 App 内评分需要使用 SKStoreProductViewController。它只会在 App 内部模态打开在 AppStore 的详情页…

windows 内存泄露和资源泄漏调试

AQTime (有x64、win32的)进行内存泄露和资源泄漏监控http://wenku.baidu.com/view/9aa1c2afdd3383c4bb4cd2c1.html x64下载&#xff1a;http://downlite.net/lp.php?coc&nAutomatedQA.AQTime.v6.21.400.x64.Cracked.WORKING-BRD Windows Leaks Detector&#xff08;好象只…

ESXi6.5环境搭建(二:ESXi 6.5环境的安装及配置)

实验目的及要求 完成VMware workstations安装&#xff0c;会应用相关操作&#xff1b;完成虚拟机中ESXI6.5平台的安装及网络环境配置&#xff1b;完成VMware vSphere Client 6.0软件在PC端的安装及配置&#xff1b;完成使用浏览器或者VMware vSphere Client 6.0中对ESXI6.5的操…

Android自定义ListView的Item无法响应OnItemClick的解决办法

转&#xff1a;如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话&#xff0c;那么默认focus是交给了子控件&#xff0c;而ListView的Item能被选中的基础是它能获取Focus&#xff0c;也就是说我们可以通过将ListView中Item中包含的所有控件的focusable属性设置…

iPA 打包小工具

2017-04-07原文链接&#xff1a;http://icofans.com/2017/04/06/%E6%A1%8C%E9%9D%A2%E6%89%93%E5%8C%85IPA%E5%B0%8F%E7%A8%8B%E5%BA%8F/对项目进行 iPA 打包导出 使用方法&#xff1a;运行后&#xff0c;将项目文件夹拖拽至主界面&#xff0c;此时项目便开始打包。打包完成后会…

ESXi6.5环境搭建(三:vSphere Client6.0安装)

实验目的及要求 完成VMware workstations安装&#xff0c;会应用相关操作&#xff1b;完成虚拟机中ESXI6.5平台的安装及网络环境配置&#xff1b;完成VMware vSphere Client 6.0软件在PC端的安装及配置&#xff1b;完成使用浏览器或者VMware vSphere Client 6.0中对ESXI6.5的操…

JavaScript arguments对象

1、在JavaScript中&#xff0c;arguments对象是比较特别的一个对象&#xff0c;实际上是当前函数的一个内置属性。arguments非常类似Array&#xff0c;但实际上又不是一个Array实例。可以通过如下代码得以证实&#xff08;当然&#xff0c;实际上&#xff0c;在函数funcArg中&a…

iOS开发之 - 好玩的富文本

周末闲着没事&#xff0c;就想着不如把那些容易遗忘的知识点整理一下&#xff0c;一来可以让有需要的朋友少走弯路&#xff0c;二来自己以后再忘记的时候也可以回头看看......但 iOS 中小冷易忘的知识点实在太多了&#xff0c;不知道该从哪里开始整理&#xff0c;“百无聊赖”逛…

sharepoint自带JS函数获取URL参数

GetUrlKeyValue 转载于:https://www.cnblogs.com/bmib/p/3139749.html

ESXi6.5环境搭建(四:虚拟机操作系统安装及配置)

实验目的及要求 完成VMware workstations安装&#xff0c;会应用相关操作&#xff1b;完成虚拟机中ESXI6.5平台的安装及网络环境配置&#xff1b;完成VMware vSphere Client 6.0软件在PC端的安装及配置&#xff1b;完成使用浏览器或者VMware vSphere Client 6.0中对ESXI6.5的操…

iOS 生成带 logo 的二维码,区域截屏保存至相册(小功能二连发 (一))

原文链接&#xff1a;http://www.jianshu.com/p/36e9f012ef39生成带 logo 的二维码 区域截屏相关 —— 由3033分享开篇 最近项目需要搞了几个相对独立的小功能&#xff0c;今天有空总结一下他们的实现思路和方法&#xff0c;并总结一点项目中帮同事解决的问题&#xff0c;在此立…

JavaScript-学习一全局变量

因为局部变量只作用于函数内&#xff0c;所以不同的函数可以使用相同名称的变量。 局部变量在函数开始执行时创建&#xff0c;函数执行完后局部变量会自动销 不限制位置的 JavaScript 变量生命周期在它声明时初始化。 局部变量在函数执行完毕后销毁。 全局变量在页面关闭后销毁…

Android 4.2真坑爹

艹~~~&#xff0c;Android4.2真坑爹&#xff0c;4.1以前的方法都不能使用了。 操蛋呢。。。转载于:https://www.cnblogs.com/liushuibufu/p/3253611.html

ESXi6.5环境搭建(五:常见问题及解决方案实验总结)

实验目的及要求 完成VMware workstations安装&#xff0c;会应用相关操作&#xff1b;完成虚拟机中ESXI6.5平台的安装及网络环境配置&#xff1b;完成VMware vSphere Client 6.0软件在PC端的安装及配置&#xff1b;完成使用浏览器或者VMware vSphere Client 6.0中对ESXI6.5的操…

《Linux4.0设备驱动开发详解》笔记--第十二章:Linux设备驱动的软件架构思想

待补充转载于:https://www.cnblogs.com/zcjboke/p/5513130.html

iOS_Development~ 添加 / 隐藏 UITabBar 右上角的小红点

原文链接&#xff1a;http://www.jianshu.com/p/de72118a49ad添加 / 隐藏 UITabBar 右上角的小红点 —— 由anticipate_91分享添加/隐藏UITabBar右上角的小红点 话不多说&#xff0c;直接上代码吧&#xff01; 1.添加tabBar的小红点 /** 添加tabBar的小红点* index&#xff1…

解决ubuntu上opengl的问题

装完ubuntu之后&#xff0c;对于opengl的程序总是出现问题&#xff0c;先将解决方案列出如下&#xff1a; http://www.linuxforums.org/forum/ubuntu-linux/175490-graphics-driver-problem.html http://superuser.com/questions/484991/nvidia-graphics-driver-in-ubuntu-12-0…

OpenStack环境搭建(一:Virtual Box 5.1 环境的安装及配置)

实验要求&#xff1a; 完成Virtual box平台安装&#xff0c;会应用相关操作&#xff1b;在virtual box虚拟平台上部署Fuel Master节点&#xff1b;在virtual box虚拟平台上部署计算节点Computer&#xff1b;在virtual box虚拟平台上部署控制节点Controller&#xff1b;在web控…