iOS Barcode Printing - black rectangle

Hi,

I'm trying to print a barcode onto a label but it just prints a black rectangle in the shape of the barcode image.

To generate the barcode I'm using the following:

            let data = "Hello".data(using: .ascii)

            let filter = CIFilter(name: "CICode128BarcodeGenerator")

            filter?.setValue(data, forKey: "inputMessage")

            return UIImage(ciImage: (filter?.outputImage)!)

When I send this to the printer using ZebraPrinter.getGraphicsUtil().printImage(...) it just prints out a black rectangle as mentioned.

I imagine it is some problem with the format of the generated barcode image as it prints out images taken from the iPads camera ok.

Any help on this would be much appreciated.

Kind Regards

Anonymous (not verified)
If we use the following API

If we use the following API from Link-OS SDK to print an image from iOS device, the accepted image type is CGImageRef.

- printImage:atX:atY:withWidth:withHeight:andIsInsideFormat:error:

Refer to the API documentation on <GraphicsUtil>

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Simon Hopkin
Hi Steven,Thanks for your

Hi Steven,

Thanks for your reply and yes I'm aware of that, I'm calling .cgImage on the UImage before passing to the print method.  Also tried .cgImage on the CIImage created by the filter but get the same black result.

Thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Let's convert the barcode

Let's convert the barcode image from ciImage to cgImage with below code, before sending to the printer. Hope this helps.

    func getBarcode() -> UIImage {

        let data = "Hello".data(using: .ascii)

        let filter = CIFilter(name: "CICode128BarcodeGenerator")

        filter?.setValue(data, forKey: "inputMessage")

//        return UIImage(ciImage: (filter?.outputImage)!)

        let output = filter?.outputImage

        return UIImage(cgImage: convertCIImageToCGImage(ciImage:output!))

    }

    func convertCIImageToCGImage(ciImage:CIImage) -> CGImage{

        let ciContext = CIContext.init()

        let cgImage:CGImage = ciContext.createCGImage(ciImage, from: ciImage.extent)!

        return cgImage

    }

    // Print barcode

    let barcodeImage = getBarcode()

    if barcodeImage != nil && barcodeImage!.cgImage != nil {

        try printer?.getGraphicsUtil().print(barcodeImage!.cgImage!, atX: 0, atY: 0, withWidth: -1, withHeight: -1, andIsInsideFormat: false)

    }

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Simon Hopkin
Hi Steven,that did the trick

Hi Steven,

that did the trick.

Many thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments