首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现二维码扫描iphone应用的摄像头视图层?

如何实现二维码扫描iphone应用的摄像头视图层?
EN

Stack Overflow用户
提问于 2013-01-22 18:45:04
回答 2查看 1.4K关注 0票数 0

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

在安卓系统中,我可以使用SurfaceView来实现这一点,这是我们可以显示相机帧的视图。在Android中,有没有什么东西可以和iPhone中的surfaceview等价物呢?如果是这样,如何做到这一点。请给我一个教程或示例链接。

EN

回答 2

Stack Overflow用户

发布于 2013-01-22 20:04:40

代码语言:javascript
复制
- (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类并添加以下代码

代码语言:javascript
复制
- (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

票数 1
EN

Stack Overflow用户

发布于 2015-08-23 03:41:39

从iOS 7开始,二维码检测在iOS中很容易使用,诀窍是告诉AVCaptureMetadataOutput实例检测类型为AVMetadataObjectTypeQRCode的对象。

实时相机预览(如果你仍然想使用它,可以访问像素)在iOS中已经有很长一段时间了,使用AVCaptureVideoPreviewLayer最容易。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14456724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档