barcodeGenerator()
Generates a barcode as an image from the descriptor.
Declaration
class func barcodeGenerator() -> any CIFilter & CIBarcodeGeneratorReturn Value
The generated image.
Discussion
This method generates a custom barcode as an image. The effect uses barcode descriptors to specify properties of the generated barcode.
The barcode generator uses the following property:
barcodeDescriptorAn instance of CIBarcodeDescriptor with the input parameters supplied.
The following code creates a filter that generates a QR code containing the text Johnny Appleseed.
func barcode(inputMessage: Data) -> CIImage {
let barcodeGenerator = CIFilter.barcodeGenerator()
barcodeGenerator.barcodeDescriptor = CIQRCodeDescriptor(payload: inputMessage, symbolVersion: 1, maskPattern: 4, errorCorrectionLevel: .levelL)!
return barcodeGenerator.outputImage!
}
let johnnyAppleseed: [UInt8] = [0x41, 0x04, 0xA6, 0xF6, 0x86, 0xE6, 0xE7, 0x92, 0x04, 0x17, 0x07, 0x06, 0xC6, 0x57, 0x36, 0x56, 0x56, 0x40, 0xEC]
let data = Data(johnnyAppleseed)
let bImage = barcode(inputMessage: data)[Image]
See Also
Related Documentation
Filters
attributedTextImageGenerator()aztecCodeGenerator()blurredRectangleGenerator()checkerboardGenerator()code128BarcodeGenerator()lenticularHaloGenerator()meshGenerator()pdf417BarcodeGenerator()qrCodeGenerator()randomGenerator()roundedRectangleGenerator()roundedRectangleStrokeGenerator()starShineGenerator()stripesGenerator()sunbeamsGenerator()