我想使用iPhone/iPad的相机扫描Code 39格式的VIN条形码。我尝试使用zxing和zbar,但它们不能很好地工作。大多数时候它们无法识别条码。有没有更好的方法可以做到这一点?或者我能做些什么来提高结果,因为我只需要扫描Code 39(用于VIN汽车)。
使用Zbar来实现这个功能。为了获得足够的分辨率进行扫描,您需要在横屏模式下扫描条形码。以下是我的设置(已经测试并且可用)。
// 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;
//disable other codes to improve performance
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology:ZBAR_CODE39 config:ZBAR_CFG_ENABLE to:1];
//only scan vertically, in the middle of the screen (also improves performance)
[reader setScanCrop:CGRectMake(0, 0.4, 1, 0.2)];
[reader setShowsZBarControls:NO];
[reader setShowsHelpOnFail:NO];
//VERY IMPORTANT: reset zoom. by default, the screen is partially zoomed in and will cause a loss of precision
reader.readerView.zoom = 1.0;
reader.readerView.allowsPinchZoom=NO;
reader.readerView.showsFPS=YES;
reader.readerView.tracksSymbols=YES;
//scan landscape only (this also improves performance)
[scanner setSymbology:ZBAR_CODE39 config:ZBAR_CFG_X_DENSITY to:0];
[scanner setSymbology:ZBAR_CODE39 config:ZBAR_CFG_Y_DENSITY to:1];
应该差不多了!祝你好运!
编辑/注:自iOS 7起,iOS框架现在包括一个条形码扫描器。我使用了这个实现方案来获得比使用Zbar更好且更容易的结果。