Rectangle bringing on camera in ZBar scanner? - iphone

How can we bring rectangle on camera for barcode scanning like red laser with scanningound? is there any built in property?I tried following:
reader.readerView.tracksSymbols = YES;
reader.readerView.trackingColor = [UIColor redColor];
[reader setShowsZBarControls:NO];
reader.readerView.tracksSymbols = TRUE;
scanner.accessibilityFrame = CGRectMake(100, 100, 200, 300);

Add the rectange as an overlay on your camera view.Here is the code:
- (IBAction) scanButtonTapped
{
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
reader.showsZBarControls = NO;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
reader.cameraOverlayView = [self CommomOverlay];
[reader release];
}
-(UIView*)CommomOverlay{
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(70,160,203,180)];
[FrameImg setImage:[UIImage imageNamed:#"overlaygraphic.png"]];
[view addSubview:FrameImg];
return view;
}
hope this will help you..:)

Did you try
reader.cameraOverlayView = overLayView;
?? i.e cameraOverlayView property of UIImagePickerController.
There you can set what ever you want. Hope this is what you want.

Related

QR code integration

I am facing some problem after integrating ZBar framework for scanning QRCodeRead on my apps. My client wants, QRCode Scanner will be in a fixed frame and must not be a PresentModalView. So I write code for fixed frame QRCode Scanner and added the reader.view on self.view, but it not working as presentModalViewController:reader. I don't know what is going wrong. I am not able to solve this issue. I have provided my code below and Sorry for my bad English.
This Code is working...
- (IBAction) scanButtonTapped
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
// present and release the controller
[self presentModalViewController:reader animated:YES];
[reader release];
}
But this Code is not working...
- (IBAction) scanButtonTapped
{
// Create new reader
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader.scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
reader.showsCameraControls = NO;
reader.showsZBarControls = NO;
[reader setWantsFullScreenLayout:NO];
reader.showsHelpOnFail = NO;
reader.showsZBarControls = NO;
[reader.view setFrame:CGRectMake(20, 134, 280, 202)];
[self.view addSubview:reader.view];
[reader release];
}
Please help me and provide a solution.Thanks in advance.

How to add a UIview above the current view controllers view?

I have an Ipad application in which i am trying to do some barcode reading processes.when i am pressing a button in the home page i am presenting the barcode reading viewcontrollers view like this`
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.sourceType=UIImagePickerControllerSourceTypeCamera;
//reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
reader.cameraOverlayView=cameraOverlay;
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
{
reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
ZBarImageScanner *scanner = reader.scanner;
reader.wantsFullScreenLayout = YES;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader.showsZBarControls = NO;
// present and release the controller
[self presentModalViewController:reader animated:YES];
//[appdel.navigationController pushViewController:reader animated:YES];
//[reader.view addSubview:collect];
[reader.view addSubview:back];
[back addTarget:self action:#selector(backpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader.view addSubview:scan];
[scan addTarget:self action:#selector(getpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader release];
and when i am pressing the scan button added to the reader view i need to add another view.for that i am doing -(IBAction)getpressed:(id)sender{[self.view addSubview:newview] }.but it is not added to the view.can anybody help me to achieve this?
`
you need to overlay to your zbar view and add that button overlay view:
//set the frame according to your requirement
aOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,480.0)];
aOverlay.backgroundColor = [UIColor clearColor];
UIButton *aBtnscan = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aBtnscan setFrame:CGRectMake(115, 435, 80, 45)];
[aBtnscan addTarget:self action:#selector(getpressed:)forControlEvents:UIControlEventTouchUpInside];
[aOverlay addSubview:aBtnscan];
reader.cameraOverlayView = aOverlay;
// You code

trying to show a new screen after image is scanned

I am running into an issue that seems so simplistic, is frustrating. I am using the zbar library to play around with scanning qr-codes. Here is my code:
- (IBAction)scanButtonTapped:(id)sender {
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = NO;
UIButton *overlay = [UIButton buttonWithType:UIButtonTypeCustom];
overlay.frame = CGRectMake(0, 0, 320, 480);
[overlay setImage:[UIImage imageNamed:#"CameraCover.png"] forState:UIControlStateNormal];
reader.cameraOverlayView = overlay;
overlay.userInteractionEnabled = YES;
[overlay addTarget:self action:#selector(beginScanning:) forControlEvents:UIControlEventTouchUpInside];
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: NO];
[reader release];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;
// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
[self pushNewScreen];
}
-(void) pushNewScreen
{
MainViewController *mainView = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
[self presentModalViewController:mainView animated:YES];
[mainView release];
}
The problem is, when pushNewScreen is called, mainView is not shown... I have gone through each line with the debugger and every line in pushNewScreen is called. Any ideas?
Instead of [self pushNewScreen]; use [self performselector:#selector(pushNewScreen) after delay:0.5f];
It will solve the problem. If not, increase the delay timing.
Thanks to A-Live, I was able to solve it using
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
instead. Hope this helps someone else!

how to set scan frame in zbar SDK?

I an using Zbar SDK and want to scan QRcode and barcode in my define frame but it is scanning in any part of screen not in my defined frame so where i am doing mistake?
I want to do scan like this in my defined frame.
http://www.visionsmarts.com/products/VSBarcodeReader/VSBarcodeReader.html
here is my code.
-(void)displayMe{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.showsZBarControls=NO;
//////////////black area/////////////////////////
UIImage *image1 = [UIImage imageNamed:#"blackscreen.png"];
UIImageView *imageLogo1 = [[UIImageView alloc] initWithImage:image1];
imageLogo1.frame = CGRectMake(0, 0, 320, 480);
cancelLabel =[[UILabel alloc]initWithFrame:CGRectMake(0,420, 320, 60)];
cancelLabel.backgroundColor = [UIColor blackColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(100,420, 100, 60)];
[btn setTitle:#"Cancel" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:18];
btn.backgroundColor=[UIColor blackColor];
[btn addTarget:self action:#selector(back)
forControlEvents:UIControlEventTouchUpInside];
[cancelLabel bringSubviewToFront:btn];
[imageLogo1 addSubview:cancelLabel];
[imageLogo1 setUserInteractionEnabled:YES];
[imageLogo1 addSubview:btn];
//reader.cameraOverlayView = btn;
///////////////line/////////////////////////////
UIImage *image = [UIImage imageNamed:#"ScannerKitLaser#2x.png"];
UIImageView *imageLogo = [[UIImageView alloc] initWithImage:image];
imageLogo.frame = CGRectMake(40, 240, 230, 10);
[imageLogo1 addSubview:imageLogo];
///////////////Configure reader///////////////////////////////
reader.cameraOverlayView = imageLogo1;
//reader.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);
//imageLogo.frame = CGRectMake(0, 0, image.size.width, image.size.height);
//imageLogo.center = CGRectMake(320/2, 460/2, image.size.width, image.size.height);
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 1];
ZBarCaptureReader *cap=[[ZBarCaptureReader alloc]init];
//cap.scanCrop=CGRectMake(300, 400, 230, 200);
cap.scanCrop=CGRectMake(100, 160, 50,60);
//cap.cameraOverlayView.frame=CGRectMake(40, 240, 230, 30);
[self presentModalViewController: reader
animated: YES];
[reader release];
Make a UIVIew (e.g. scanView) object and make it as your customize area. Where u want to get scan area there should be transparent area or In image transparent cut.
use this
reader.cameraOverlayView = scanView;
Also disable to all mode except Portrait mode.
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
Full e.g. code
In MyScanCode.h file
{ZBarReaderViewController *reader;}
#property (nonatomic, strong) IBOutlet UIView *scanView;
In MyScanCode.m file
- (void) readCode{
reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationPortrait);
#if !(TARGET_IPHONE_SIMULATOR)
reader.cameraOverlayView = scanView;
reader.showsZBarControls = NO;
#endif
reader.wantsFullScreenLayout = NO;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology:ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
[self presentModalViewController:reader animated:NO];
}
Instead of using ZBarReaderViewController, try using ZBarReaderView. This worked for me and saved my lot of time. Hope it helps you.
ZBarReaderView*reader = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader = [reader initWithImageScanner:scanner];
reader.readerDelegate = self;
reader.tracksSymbols = YES;
reader.frame = CGRectMake(20, 126-88, 283, 347);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});
[self.view addSubview:reader];

Iphone web view during use of Camera

Is it possible to open webview during use of camera in app.if it is possible plz let me know.
You could try:
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject
{
//NSLog(#"008 ::Create Postcard :: start photo camera");
if ((![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil)) {
return NO;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
UIView *overlay = [[UIView alloc]initWithFrame:CGRectMake(x, y, w, h)];
// overlay.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
// overlay.backgroundColor = [UIColor redColor];
{create your webview here}
[overlay addSubview:webview];
[webview release];
[picker.cameraOverlayView = overlay;
[controller presentModalViewController:picker animated:YES];
return YES;
}
If you have enough recources on the phone it might could work i guess