Reputation: 1532
I have been searching for solutions to scanning a 1d barcode and came up with the following answer: QR Code Scanning in ios application
I am developing for iOS 8 and the second answer to the above question addresses the fact that we no longer need to use a third party library. This seems to be relatively straight forward.
There are applications out there that scan a barcode and you can then view the barcode on the device. I am hypothesising that they are creating a UIImage from the scanned barcode. However I am unsure how I can go about implementing the same thing in my application.
Does anyone know of any code samples or libraries that handle this type of behaviour?
Upvotes: 2
Views: 15021
Reputation: 1532
For those of you using swift to create a barcode scanner, here is a really good tutorial:
http://shrikar.com/blog/2015/01/24/implementing-barcode-scanning-in-ios8-with-swift/
Upvotes: 0
Reputation: 458
There are two components to a barcode: 1) the image of the barcode itself and 2) the data that can be extracted from the barcode. iOS 7+ supports finding a barcode in an image and also extracting the data from that image without external libraries. There are many strong tutorials and answers related to barcode recognition but you are probably looking for this one: http://www.infragistics.com/community/blogs/torrey-betts/archive/2013/10/10/scanning-barcodes-with-ios-7-objective-c.aspx
I can think of two ways to achieve what you wish, capturing a barcode then displaying it on-screen: 1) crop the larger image where the barcode was detected so that only the barcode is left, then display that, or 2) once a barcode is detected create a new barcode. The advantage of the first method is you can crop slightly larger so the barcode will clearly appear like the original but any imperfections (stains, shadows, etc...) will be left. The advantage of the second is you will have a crystal clear barcode but the user experience might appear a little disjointed (or it may look like magic: you'll have "cleaned up" a smudged barcode). Choosing one depends on the type of user experience you wish for.
If you choose to crop the image tell iOS to detect the barcode, as per the tutorial above, and when the barcode is detected use the the bounds of the barcode object to crop the underlying overall image, a UIImage object. If you choose to create a barcode using the data you extracted from the original barcode it looks like you will need a library. There is a question that addresses that here: Barcode Generation from within iOS App
Upvotes: 5
Reputation: 5183
Try this tutorial this worked for me for scanning QR code
http://www.appcoda.com/qr-code-ios-programming-tutorial/
Upvotes: 0