EFQRCode



NOTE: Want to explore EFQRCode interactively? Get our user guide as Swift Playground here.

1. Recognition

There are two equivalent ways:

EFQRCode is a lightweight, pure-Swift library for generating pretty QRCode image with input watermark or icon and recognizing QRCode from image, it is based on CoreImage. This project is inspired by qrco.

or

  1. A flutter plugin can be used to generate QRCode. Example # Getting Started #. This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
  2. EFQRCode is a lightweight, pure-Swift library for generating pretty QRCode image with input watermark or icon and recognizing QRCode from image, it is based on CoreGraphics, CoreImage and ImageIO. EFQRCode provides you a better way to operate QRCode in your app, it works on iOS, macOS, watchOS and tvOS, and it is available through CocoaPods.

Because of the possibility that more than one QR code exist in the same image, the return value is a [String]. If the returned array is empty, we could not recognize/didn’t find any QR code in the image.

2. Generation

Again, there are two equivalent ways of doing this:

or

The return value is of type CGImage?. If it is nil, something went wrong during generation.

Parameters Explained

content: String?

EFQRCode

Content is a required parameter, with its capacity limited at 1273 characters. The density of the QR-lattice increases with the increases of the content length. For example:

10 characters250 characters

mode: EFQRCodeMode

Mode of QR Code is defined as EFQRCodeMode:

nilgrayscalebinarization

binarization threshold:

mode nil0.30.50.8

inputCorrectionLevel: EFInputCorrectionLevel

Percent of tolerance (which we default to H defined below) has 4 different levels: L 7% / M 15% / Q 25% / H 30%.

Comparison of different input correction levels (generating for the same content):

LMQH

size: EFIntSize

NOTE: will be ignored if magnification is not nil

Length and height of the generated QR code, defaults to 256 by 256. EFIntSize is just like CGSize, but width and height are Int instead of CGFloat.

234 * 234312 * 234

magnification: EFIntSize?

Magnification is defined as the ratio of actual size to the smallest possible size, and defaults to nil.

Directly setting the size parameter results in low resolution QR code images, so setting the magnification is recommended instead. If you already have a desired size in mind, we have two helpers methods at your disposal to calculate the magnification that results in the closet dimension: EFQRCodeGenerator.maxMagnification(lessThanOrEqualTo:) and EFQRCodeGenerator.minMagnification(greaterThanOrEqualTo:).

size 300magnification 9

backgroundColor: CIColor/CGColor

Background color, defaults to white.

foregroundColor: CIColor/CGColor

Foreground color (for code points), defaults to black.

Foreground color set to redBackground color set to gray

icon: CGImage?

Icon image in the center of QR code image, defaults to nil.

iconSize: CGFloat?

Size of icon image, defaults to 20% of QR code size if nil.

Default 20% sizeSet to 64

watermark: CGImage?

Background watermark image, defaults to nil.

watermarkMode: EFWatermarkMode

Position of watermark in the QR code, defaults to EFWatermarkMode.scaleAspectFill. Think of the generated QR code like UIImageView and EFWatermarkMode as UIView.ContentMode.

isWatermarkOpaque: Bool

Treat watermark image as opaque, defaults to false (use transparency).

falsetrue

Efr Codec

pointOffset: CGFloat

WARNING: Generated QR code might be hard to recognize with this parameter.

Foreground point offset, defaults to 0.

00.5

pointShape: EFPointShape

Shape of foreground code points, defaults to EFPointShape.square.

squarecirclediamond

3. Generation from GIF

First you should get the complete Data of a GIF file

EFQRCode

NOTE: You shall not get Data from UIImage as it only provides the first frame.

Then you can create GIF QRCode with EFQRCode.generateGIF:

EFQRCode
ParameterDescription
generatorREQUIRED, an EFQRCodeGenerator instance with other settings
dataREQUIRED, encoded input GIF
delayOutput QRCode GIF delay, emitted means no change
loopCountTimes looped in GIF, emitted means no change

Eforcedemo

The generator here is an instance of EFQRCodeGenerator, as demonstrated above, for configuring other parameters for individual frames in GIF. You can checkout the demo projects for more information.

Qr Code For Android

Efa

The result (seizure WARNING) will be something like this:

Now you can get the complete data of output QRCode GIF, next we can save it to local path / system photo library / upload to server or some other things you want to do;