I want to scan a static UIImage using Zbar sdk, it gives error i.e. ZBarSymbol is Null
I also checked
ZBarReaderController: UIImagePickerController
But as it is subclass of UIImagePickerController and i don't want to use UIImagePickerController at all as i just want to scan UIImage that i have reference in my application.. I searched allot for this problem but did not got any help..
I also tried for ZBarImageScanner as,
- (void) scanFromUIImage: (UIImage *)img{
// setup scaner
ZBarImageScanner *scanner = [[ZBarImageScanner alloc] init];
Settings *settings = [Settings globalSettings];
//ZBarImageScanner *scanner = reader.scanner;
BOOL haveLongLinear = NO;
for(NSString *str in settings.enabledSymbologies) {
NSNumber *value = [settings.enabledSymbologies objectForKey: str];
BOOL enable = value.boolValue;
zbar_symbol_type_t sym = [str integerValue];
[scanner setSymbology: sym
config: ZBAR_CFG_ENABLE
to: enable];
if(sym == ZBAR_EAN13) {
// show EAN variants as such
[scanner setSymbology: ZBAR_UPCA
config: ZBAR_CFG_ENABLE
to: enable];
[scanner setSymbology: ZBAR_UPCE
config: ZBAR_CFG_ENABLE
to: enable];
[scanner setSymbology: ZBAR_ISBN13
config: ZBAR_CFG_ENABLE
to: enable];
}
haveLongLinear |= enable && sym > ZBAR_COMPOSITE && sym != ZBAR_QRCODE;
}
ZBarImage *zbimg = [[ZBarImage alloc] initWithCGImage:img.CGImage];
UIImage *image = screenShot;
id <NSFastEnumeration> results = [scanner scanImage:zbimg];
//NSLog(@"-------> %@",results);
ZBarSymbol *sym = nil;
for(sym in results)
break;
assert(sym);
assert(image);
if(!sym || !image)
return;
Barcode *barcode =
[NSEntityDescription insertNewObjectForEntityForName: @"Barcode"
inManagedObjectContext: context];
assert(barcode);
if(!barcode)
return;
assert(currentFolder);
// wana save safari screen shot to Safari Folder
Folder *folder = nil;
folder = [Folder defaultFolderInContext: context];
if(folder != currentFolder) {
[currentFolder release];
currentFolder = [folder retain];
}
barcode.folder = currentFolder;
barcode.date = [NSDate date];
barcode.image = image;
barcode.symbol = sym;
barcode.type = [NSNumber numberWithInteger: sym.type];
barcode.data = sym.data;
barcode.name = nil;
barcode.thumb = nil;
NSArray *stack = nav.viewControllers;
BarcodeListController *_list = nil;
if(stack.count > 1) {
_list = [stack objectAtIndex: 1];
if(![_list isKindOfClass: [BarcodeListController class]] ||
_list.folder != currentFolder)
_list = nil;
}
if(_list)
[nav popToViewController: _list
animated: NO];
else {
[nav popToRootViewControllerAnimated: NO];
_list = [[[BarcodeListController alloc]
initWithFolder: currentFolder]
autorelease];
[nav pushViewController: _list
animated: NO];
}
UIViewController *detail =
[[BarcodeDetailController alloc]
initWithBarcode: barcode];
[nav pushViewController: detail
animated: NO];
[detail release];
if(settings.autoLink)
[self performSelector: @selector(autoLink:)
withObject: barcode
afterDelay: 0.25];
[window.rootViewController
adDismissModalViewController:self.safari
animated: YES];
[self performSelector: @selector(genThumb:)
withObject: barcode
afterDelay: .5];
}