I want to know if it is possible when using Zbar barcode scanning within an iPhone/iOS app to add some sort or crosshairs or other visual indicator to the screen to assist users in aiming their camera onto a QR code?

- 232,980
- 40
- 330
- 338

- 7,856
- 14
- 81
- 132
-
1I agree to the adding of ZBar as a tag. It's one of the best open source bar code readers for the iphone. – JeroenEijkhof Jun 06 '11 at 07:44
2 Answers
That is best accomplished with a transparent PNG. Just import it to your project and then create a new UIImageView
that you give to the reader.
I did this to add a logo:
// Create the reader
self.reader = [ZBarReaderViewController new];
self.reader.readerDelegate = self;
// Create image for adding a logo :)
UIImage *image = [UIImage imageNamed:@"scan_logo.png"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
// Configure reader
self.reader.cameraOverlayView = imageLogo;
To get the image in the center just change the frame positioning from:
imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
To something like:
imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);

- 2,232
- 2
- 25
- 39
-
-
Sorry for the late response. No unfortunately not since your computer doesn't have a camera, it will simply give you the option of choosing a picture to scan. Simply save a barcode to your iPhone/iPad simulators picture library and it will appear when you test. Also if the answer I gave was correct please consider marking it as the correct answer. – JeroenEijkhof Jun 09 '11 at 06:52
FWIW what I did in my app is to extend the ZBarReaderViewController class, set my new class as the ZBarReaderDelegate also, and then put JeroenEijkhof's code into my init override:
- (id) init
{
self = [super init];
if( self ) {
self.readerDelegate = self;
UIImage *image = [UIImage imageNamed:...
...
}
return self;
}
This gave me the ability to control other aspects of the view, such as customizing the navigation controller on viewDidLoad
and viewWillAppear
since I was implementing the camera view in a NavigationController view stack and wanted the ability to add the titlebar, toolbar, etc. instead of presenting it modally, as the zbar docs demonstrate.

- 5,514
- 5
- 28
- 38