我正在做一个 iOS 应用程序,我必须在其中扫描条形码。我使用 ZBarReaderViewController 来扫描条形码。有时它会准确地给出结果,但有时会给出像&7&#,Ac9这样的未知值。我的图像是我的代码是
-(IBAction)scanBarCode:(id)sender
{
reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale >= 1136)
[reader.readerView setScanCrop:(CGRect){ { 0.25, 0.08 }, { 0.07, 0.84} }];//.25
else
[reader.readerView setScanCrop:(CGRect){ { 0.23, 0.08 }, { 0.09, 0.84} }];
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];*/
//swetha test
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
// Enable EAN 13
[scanner setSymbology: ZBAR_EAN13
config: ZBAR_CFG_ENABLE
to: 1];
// Enable UPC-A
[scanner setSymbology: ZBAR_UPCA
config: ZBAR_CFG_ENABLE
to: 1];
// Enable Code 128
[scanner setSymbology: ZBAR_CODE128
config: ZBAR_CFG_ENABLE
to: 1];
[self presentViewController:reader animated:YES completion:nil];
[reader release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
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
serialnumber.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*!)
barcodeClicked = 0;
[picker dismissViewControllerAnimated:YES completion:nil];
}
如果我不清楚,请告诉我。提前致谢 。