How to Generate a Barcode from a String in Swift

How to get a quality barcode image from string in ios, swift

When the CIImage is converted to a UIImage it does so with a fixed size that is determined by the CIImage, if you subsequently try to scale this image up, say by assigning it to a UIImageView, then you will get the typical pixellation associated with scaling up a bitmap.

Transform the image before assigning it to the UIImage

if let barImage = filter.outputImage {
let transform = CGAffineTransformMakeScale(5.0, 5.0)
let scaled = barImage.imageByApplyingTransform(transform)
return(UIImage(CIImage: scaled))
}

Barcode string value when using the Vision Framework of iOS11

It seems that now you can get a decoded string from a barcode using new payloadStringValue property of VNBarcodeObservation introduced in iOS 11 beta 5.

if let payload = barcodeObservation.payloadStringValue {
print("payload is \(payload)")
}

Barcode Generation from within iOS App

The only free library to do this is Cocoa-Touch-Barcodes, which is a fork of cocoabarcodes. If you are considering commercial libraries, there is one called iPhone Barcode Generator.

update Check this objective-c port of ZXing: https://github.com/TheLevelUp/ZXingObjC



Related Topics



Leave a reply



Submit