以下是我在vIEwDIDLoad方法中加载扫描程序的方法:
//Initialize Laser VIEw laserVIEw = [[UIVIEw alloc] init]; laserVIEw.autoresizingMask = UIVIEwautoresizingFlexibletopmargin|UIVIEwautoresizingFlexibleleftmargin|UIVIEwautoresizingFlexibleRightmargin|UIVIEwautoresizingFlexibleBottommargin; laserVIEw.layer.bordercolor = [UIcolor redcolor].CGcolor; laserVIEw.layer.borderWIDth = 8; laserVIEw.layer.cornerRadius = 10; [self.vIEw addSubvIEw:laserVIEw]; //Start Session scannerSession = [[AVCaptureSession alloc] init]; scannerDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVIDeo]; //define Error Messages NSError *error = nil; //define input scannerinput = [AVCaptureDeviceinput deviceinputWithDevice:scannerDevice error:&error]; //Check if Device has a Camera if (scannerinput) { [scannerSession addinput:scannerinput]; } else { NSLog(@"Error: %@",error); } // Locks the configuration BOol success = [scannerDevice lockForConfiguration:nil]; if (success) { if ([scannerDevice isautoFocusRangeRestrictionSupported]) { // Restricts the autofocus to near range (new in iOS 7) [scannerDevice setautoFocusRangeRestriction:AVCaptureautoFocusRangeRestrictionNear]; } } // unlocks the configuration [scannerDevice unlockForConfiguration]; //define Output & Metadata Object Types scannerOutput = [[AVCaptureMetadataOutput alloc] init]; [scannerOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; [scannerSession addOutput:scannerOutput]; scannerOutput.MetadataObjectTypes = [scannerOutput availableMetadataObjectTypes]; //Create VIDeo PrevIEw Layer scannerPrevIEwLayer = [AVCaptureVIDeoPrevIEwLayer layerWithSession:scannerSession]; scannerPrevIEwLayer.frame = self.vIEw.bounds; scannerPrevIEwLayer.vIDeoGravity = AVLayerVIDeoGravityResizeAspectFill; [self.vIEw.layer addSublayer:scannerPrevIEwLayer]; //Start Session [scannerSession startRunning]; [self.vIEw bringSubvIEwToFront:cancelbutton]; [self.vIEw bringSubvIEwToFront:laserVIEw];
和:
- (voID)captureOutput:(AVCaptureOutput *)captureOutput dIDOutputMetadataObjects:(NSArray *)MetadataObjects fromConnection:(AVCaptureConnection *)connection { //Prepare Laser VIEw CGRect laser = CGRectZero; //Format Date NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"M/d"]; //Format Time NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init]; [timeFormatter setDateFormat:@"h:ma"]; //define barcode Types to Recognize AVMetadataMachineReadableCodeObject *barCodeObject; Nsstring *IDNumber = nil; NSArray *barCodeTypes = @[AVMetadataObjectTypeCode39Code]; if ([MetadataObjects count] > 1) { NSLog(@"%lu barcodes Found.",(unsigned long)[MetadataObjects count]); } //Get String Value For Every barcode (That Matches The Type We're Looking For) for (AVMetadataObject *Metadata in MetadataObjects) { for (Nsstring *type in barCodeTypes) { //If The barcode Is The Type We Need Then Get Data if ([Metadata.type isEqualToString:type]) { barCodeObject = (AVMetadataMachineReadableCodeObject *)[scannerPrevIEwLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)Metadata]; laser = barCodeObject.bounds; IDNumber = [(AVMetadataMachineReadableCodeObject *)Metadata stringValue]; break; } } // If IDNumber Found if (IDNumber != nil) { //Stop Session [scannerSession stopRunning]; [self vibrate]; NSLog(@"ID: %@",IDNumber); break; } //If IDNumber Is Not Found else { NSLog(@"No ID Found."); } } //Update Laser laserVIEw.frame = laser;}解决方法 尝试放大一点… vIDeoDevice.vIDeoZoomFactor = 2.0; 总结
以上是内存溢出为你收集整理的为什么使用新的iOS 7 API扫描条形码真的很慢?全部内容,希望文章能够帮你解决为什么使用新的iOS 7 API扫描条形码真的很慢?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)