0

我正在编写要扫描 qr 码的 iphone 应用程序。我有 QR 码库来扫描 QR 码。现在我想给我的iPhone应用程序提供二维码扫描接口。

在 Android 中,我可以使用SurfaceView我们可以显示相机帧的视图来实现这一点。iPhone中是否有与Android中的surfaceview等效的东西?如果是这样怎么做。请给我一个教程或示例链接。

4

2 回答 2

1
- (IBAction)TakePicture:(id)sender {

// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

// Set source to the camera
imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

    // Delegate is self
    imagePicker.delegate = self;

    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];     

    // Insert the overlay:
    imagePicker.cameraOverlayView = overlay;

   // Allow editing of image ?
    imagePicker.allowsImageEditing = YES;
    [imagePicker setCameraDevice:
    UIImagePickerControllerCameraDeviceFront];
    [imagePicker setAllowsEditing:YES];
    imagePicker.showsCameraControls=YES;
    imagePicker.navigationBarHidden=YES;
    imagePicker.toolbarHidden=YES;
    imagePicker.wantsFullScreenLayout=YES;

    self.library = [[ALAssetsLibrary alloc] init];

    // Show image picker
    [self presentModalViewController:imagePicker animated:YES];
}

创建一个 UIView 类并添加此代码

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code


        // Clear the background of the overlay:
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        // Load the image to show in the overlay:
        UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
        UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
        overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
        [self addSubview:overlayGraphicView];

    }
    return self;
}

您也可以参考这个链接:http ://www.musicalgeometry.com/?p=821

于 2013-01-22T12:04:39.560 回答
0

自 iOS 7 以来,iOS 中很容易使用 QR 码检测,诀窍是告诉AVCaptureMetadataOutput实例检测类型为 的对象AVMetadataObjectTypeQRCode

实时相机预览(如果您仍想使用它,可以访问像素)在 iOS 中已经存在很长时间了,最​​简单的AVCaptureVideoPreviewLayer.

有关示例,请参见此处http://www.appcoda.com/qr-code-reader-swift/

于 2015-08-22T19:41:38.587 回答