if ([
self.captureSession canSetSessionPreset:AVCaptureSessionPreset1280x720]) {
self.captureSession.sessionPreset = AVCaptureSessionPreset1280x720; w =
1280.f; h =
720.f; }
else if ([
self.captureSession canSetSessionPreset:AVCaptureSessionPreset640x480]) {
self.captureSession.sessionPreset = AVCaptureSessionPreset640x480; w =
960.f; h =
540.f; } captureOutput.metadataObjectTypes = [captureOutput availableMetadataObjectTypes]; CGRect bounds = [[UIScreen mainScreen] bounds];
if (!
self.prevLayer) {
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:
self.captureSession]; }
self.prevLayer.frame = bounds;
self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [
self.view.layer insertSublayer:
self.prevLayer atIndex:
0]; CGFloat p1 = bounds.size.height/bounds.size.width; CGFloat p2 = w/h; CGRect cropRect = CGRectMake(CGRectGetMinX(_cropRect) - kQRReaderScanExpandWidth, CGRectGetMinY(_cropRect) - kQRReaderScanExpandHeight, CGRectGetWidth(_cropRect) +
2*kQRReaderScanExpandWidth, CGRectGetHeight(_cropRect) +
2*kQRReaderScanExpandHeight);
if (fabs(p1 - p2) <
0.000001) { captureOutput.rectOfInterest = CGRectMake(cropRect.origin.y /bounds.size.height, cropRect.origin.x/bounds.size.width, cropRect.size.height/bounds.size.height, cropRect.size.width/bounds.size.width); }
else if (p1 < p2) { CGFloat fixHeight = bounds.size.width * w / h; CGFloat fixPadding = (fixHeight - bounds.size.height)/
2; captureOutput.rectOfInterest = CGRectMake((cropRect.origin.y + fixPadding)/fixHeight, cropRect.origin.x/bounds.size.width, cropRect.size.height/fixHeight, cropRect.size.width/bounds.size.width); }
else { CGFloat fixWidth = bounds.size.height * w / h; CGFloat fixPadding = (fixWidth - bounds.size.width)/
2; captureOutput.rectOfInterest = CGRectMake(cropRect.origin.y/bounds.size.height, (cropRect.origin.x + fixPadding)/fixWidth, cropRect.size.height/bounds.size.height, cropRect.size.width/fixWidth); }
识别二维码图片
2/6 首页 上一页 1 2 3 4 5 6 下一页 尾页