EANBarcodeGenerator provides CIFilter CIEANBarcodeGenerator
for generating EAN-13, EAN-8 and UPC-A barcodes. This generator was created for iOS application PokeWall (https://itunes.apple.com/us/app/pokewall/id1449455385)
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 9.0+
EANBarcodeGenerator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EANBarcodeGenerator'
Import Framework:
import EANBarcodeGenerator
Register CIFilter:
CIEANBarcodeGenerator.register()
you can place this code for example into method of ApplicationDelegate application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)
Generate barcode:
let filter = CIFilter(name: "CIEANBarcodeGenerator")
filter?.setValue("5901234123457", forKey: "inputMessage")
let image = filter?.outputImage
outputImage
represents CIImage with width: 95 pixels, height: 32 pixels. To get UIImage with certain size, you can use next code:
let scaleX = uiImageSize.width / ciImage.extent.width
let scaleY = uiImageSize.height / ciImage.extent.height
let uiImage = UIImage(ciImage: ciImage.transformed(by: CGAffineTransform(scaleX: scaleX, y: scaleY)))
Sergey Bayborodov, ampirator@gmail.com
EANBarcodeGenerator is available under the MIT license. See the LICENSE file for more info.