简体   繁体   English

如何实现相机视图层的二维码扫描iPhone应用程序?

[英]how to implement camera view layer for qr code scanning iphone application?

I am writing iphone application where i want qr code scanning.I have QR code library to scan QR code. 我正在编写要扫描二维码的iPhone应用程序。我有QR码库来扫描QR码。 And now I want to give QR code scanning interface to my iPhone application. 现在,我想为我的iPhone应用程序提供QR码扫描界面。

In Android I could achieve this using SurfaceView that is the view where we can show camera frames. 在Android中,我可以使用SurfaceView (可以在其中显示相机框架的视图)实现此目的。 Is there anything available in iPhone equilvalent to surfaceview in Android? iPhone是否有与Android中的Surfaceview等效的功能? If so how to do this. 如果是这样,该如何做。 Please give me a tutorial or example links. 请给我一个教程或示例链接。

- (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];
}

Make a UIView class and add this code 创建一个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;
}

You can also refer to this link: http://www.musicalgeometry.com/?p=821 您也可以参考以下链接: http : //www.musicalgeometry.com/?p=821

QR code detection is readily available in iOS since iOS 7, the trick is to tell a AVCaptureMetadataOutput instance to detect objects with type AVMetadataObjectTypeQRCode . 自iOS 7起,iOS中AVMetadataObjectTypeQRCode提供QR码检测功能,其窍门是告诉AVCaptureMetadataOutput实例检测类型为AVMetadataObjectTypeQRCode对象。

Live camera preview (with access to pixels if you still want to use that) is in iOS for a long time, easiest with AVCaptureVideoPreviewLayer . 实时摄像头预览(如果您仍要使用像素,则可以访问像素)已经存在于iOS中很长时间了,而使用AVCaptureVideoPreviewLayer最为容易。

See here for an example http://www.appcoda.com/qr-code-reader-swift/ 请参阅此处的示例http://www.appcoda.com/qr-code-reader-swift/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM