0

嗨,如果我用这个制作图像捕获屏幕

-(void)initializecam{
     AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;

CALayer *viewLayer = self.vImagePreview.layer;
NSLog(@"viewLayer = %@", viewLayer);

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
    // Handle the error appropriately.
    NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];
_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];

[session addOutput:_stillImageOutput];
[session startRunning];
}

所以现在我想使用zbar条码扫描。有人知道怎么做吗。我搜索了很多,但他们使用图像捕获视图以及如何修改该视图。我需要的是我有一个图像[不在相机胶卷中],我想通过 zbar 扫描它,没有图像捕获视图或任何东西。请帮忙。除了 zbar 之外,还有其他免费库可以做到这一点吗?

4

1 回答 1

1

可以通过这个来完成

 - (void)scan {
// ADD: present a barcode reader that scans from the camera feed

    ZBarReaderController *reader = [ZBarReaderController new];
    reader.readerDelegate = self;
    ZBarImageScanner *scanner = reader.scanner;

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    CGImageRef imgCG = self.imgCameraView.image.CGImage;

id<NSFastEnumeration> results = [reader scanImage:imgCG];
ZBarSymbol *symbol = nil;
for(ZBarSymbol *symbolF in results){
    // EXAMPLE: just grab the first barcode
    symbol=symbolF;
    break;
}

if([symbol.data length]>0){
    NSLog(@"Bar Code ID = %@",symbol.data);
    self.ticketCode=symbol.data;

    [self verifybarCode];
    self.vImagePreview.hidden=FALSE;
}
else
{
[[iToast makeText:AMLocalizedString(@"Image Is Not Properly Scanned\nTry Again", nil)] show];
self.vImagePreview.hidden=FALSE;
}

}

以前我正在服用 ZBarReaderViewController

于 2013-11-20T10:26:14.970 回答