Reputation: 7804
Hi if i make a image capture screen with this
-(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];
}
So now i want to use zbar bar code scanning. Any one know how to do this. I searched a lot but all there is they use the image capture view and how to modify that view. All i need is that i have an image[not in camera roll] and i want to scan it by zbar no image capture view or anything. Please help. Is there is any other free library except zbar to do this??
Upvotes: 0
Views: 1017
Reputation: 7804
it can be done by this
- (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;
}
}
Previously i was taking ZBarReaderViewController
Upvotes: 1