关于iOS原生条形码扫描,你需要注意的两三事
- f(i,j)=0.30R(i,j)+0.59G(i,j)+0.11B(i,j))??
- -?(BOOL)startReading?{?
- ????_isReading?=?YES;?
- ????NSError?*error;?
- ????AVCaptureDevice?*captureDevice?=?[AVCaptureDevice?defaultDeviceWithMediaType:AVMediaTypeVideo];?
- ?
- ????AVCaptureDeviceInput?*input?=?[AVCaptureDeviceInput?deviceInputWithDevice:captureDevice?error:&error];?
- ?
- ????if?(!input)?{?
- ????????NSLog(@"%@",?[error?localizedDescription]);?
- ????????return?NO;?
- ????}?
- ?
- ????_captureSession?=?[[AVCaptureSession?alloc]?init];?
- ????//?Set?the?input?device?on?the?capture?session.?
- ????[_captureSession?addInput:input];?
- ?
- ????AVCaptureMetadataOutput?*captureMetadataOutput?=?[[AVCaptureMetadataOutput?alloc]?init];?
- ????[_captureSession?addOutput:captureMetadataOutput];?
- ?
- ????//?Create?a?new?serial?dispatch?queue.?
- ????dispatch_queue_t?dispatchQueue;?
- ????dispatchQueue?=?dispatch_queue_create("myQueue",?NULL);?
- ????[captureMetadataOutput?setMetadataObjectsDelegate:self?queue:dispatchQueue];?
- ?
- ????if?(self.qrcodeFlag)?
- ????????[captureMetadataOutput?setMetadataObjectTypes:[NSArray?arrayWithObject:AVMetadataObjectTypeQRCode]];?
- ????else?
- ????????[captureMetadataOutput?setMetadataObjectTypes:[NSArray?arrayWithObjects:AVMetadataObjectTypeEAN13Code,?AVMetadataObjectTypeEAN8Code,?AVMetadataObjectTypeCode128Code,?AVMetadataObjectTypeQRCode,?nil]];?
- ?
- ????_videoPreviewLayer?=?[[AVCaptureVideoPreviewLayer?alloc]?initWithSession:_captureSession];?
- ????[_videoPreviewLayer?setVideoGravity:AVLayerVideoGravityResizeAspectFill];?
- ????[_videoPreviewLayer?setFrame:self.view.layer.bounds];?
- ????[self.view.layer?addSublayer:_videoPreviewLayer];?
- ?
- ????[_captureSession?startRunning];?
- ?
- ????return?YES;?
- }?
- ?
- ?
- -(void)stopReading{?
- ????[_captureSession?stopRunning];?
- ????_captureSession?=?nil;?
- ????[_videoPreviewLayer?removeFromSuperlayer];?
- }?
- ?
- -(void)captureOutput:(AVCaptureOutput?*)captureOutput?didOutputMetadataObjects:(NSArray?*)metadataObjects?
- ??????fromConnection:(AVCaptureConnection?*)connection?
- {?
- ????if?(!_isReading)?return;?
- ?
- ????if?(metadataObjects?!=?nil?&&?[metadataObjects?count]?>?0)?{?
- ????????AVMetadataMachineReadableCodeObject?*metadataObj?=?[metadataObjects?objectAtIndex:0];?
- ?
- ????????Do?Something....?
- ????}?
- }?
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。