2014-04-25 1 views
1

내 IOS 응용 프로그램 중 하나에서 바코드 스캐너를 사용하려고합니다. 바코드 스캐너를 성공적으로 구현했습니다.AVFoundation을 사용하여 스캐닝 경계를 설정하는 방법

현재 바코드 스캐닝은 전체 화면으로 만 표시됩니다. 하지만 내가 원하는 것은 비디오를 전체 화면으로보아야하고 바코드는 특정 부분에서만 스캔해야한다는 것입니다. 즉, 해당 부분에 바코드가 있으면 그 부분 만 표시해야합니다. 당신이 무엇을

session=[[AVCaptureSession alloc]init]; 
device=[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
NSError *error=nil; 

input=[AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
if (input) { 
    [session addInput:input]; 
} 
else{ 
    NSLog(@"Errod : %@",error); 
} 

output=[[AVCaptureMetadataOutput alloc]init]; 
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; 
[session addOutput:output]; 

output.metadataObjectTypes=[output availableMetadataObjectTypes]; 

prevLayer=[AVCaptureVideoPreviewLayer layerWithSession:session]; 
[prevLayer setFrame:self.view.bounds]; 
[prevLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 
[self.view.layer addSublayer:prevLayer]; 

[session startRunning]; 

[self.view bringSubviewToFront:self.lblCode]; 
[self.view bringSubviewToFront:self.imgShade1]; 
[self.view bringSubviewToFront:self.imgShade2]; 
+0

어디에서 해결할 수 있습니까? – SergioM

답변

0

이것은 이후 : 다음은 내 현재 코드 areaOfInterest가 CGRect입니다

CGRect visibleMetadataOutputRect = [prevLayer metadataOutputRectOfInterestForRect:areaOfInterest]; 

output.rectOfInterest = visibleMetadataOutputRect; 

. 희망이 문제를 해결합니다.

0

어쩌면이 질문에 답하는 것이 늦을 지 모르지만 나는이 문제를 직접 극복했습니다. 그래서 나중에 다른 사람들을 도울 수 있기를 바랍니다.

키워드는 AVCaptureMetadataOutput의 rectOfIerest이며, 여기에 제가 설정 한 방법이 있습니다.

CGSize size = self.view.bounds.size; 
_output.rectOfInterest = CGRectMake(cropRect.origin.y/size.height, cropRect.origin.x/size.width, cropRect.size.height/size.height, cropRect.size.width/size.width); 

자세한 내용 들어, Apple Inc.의

행운을 빕니다에서 문서를 확인할 수 있습니다. :)

관련 문제