二维码相关

一、生成二维码

1、生成过滤器

CIFilter*filer = [CIFilterfilterWithName:@"CIQRCodeGenerator"];

2、恢复默认设置

[filersetDefaults];

3、向二维码中添加数据

NSString*string = [NSStringstringWithFormat:@"傻屌"];

NSData*data = [stringdataUsingEncoding:NSUTF8StringEncoding];

[filersetValue:dataforKeyPath:@"inputMessage"];

4、从过滤器中获取到二维码

CIImage*ciImage =  [fileroutputImage];

5、把获取到的二维码数据加载到视图中

self.CodeImageView.image= [UIImageimageWithCIImage:ciImage];

二、扫描二维码

// 1、创建捕捉会话

AVCaptureSession*session = [[AVCaptureSessionalloc]init];

// 2、设置捕捉的输入设备

AVCaptureDevice*device = [AVCaptureDevicedefaultDeviceWithMediaType:AVMediaTypeVideo];

AVCaptureDeviceInput*inPutDevice = [AVCaptureDeviceInputdeviceInputWithDevice:deviceerror:nil];

[sessionaddInput:inPutDevice];

// 3、设置捕捉的输出数据

AVCaptureMetadataOutput*MetadataOutput = [[AVCaptureMetadataOutputalloc]init];

[MetadataOutputsetMetadataObjectsDelegate:selfqueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)];

[sessionaddOutput:MetadataOutput];

[MetadataOutputsetMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];

// 4、添加捕捉图层

AVCaptureVideoPreviewLayer*preViewLayer = [AVCaptureVideoPreviewLayerlayerWithSession:session];

preViewLayer.frame=self.view.bounds;

[self.view.layeraddSublayer:preViewLayer];

// 5、执行捕捉

[sessionstartRunning];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 如何播放视频iOS提供了MPMoviePlayerController、MPMoviePlayerViewCont...
    醉叶惜秋阅读 4,834评论 0 0
  • 1、为什么使用二维码? 在手机客户端应用里,对二维码的使用也比较多。常见的功能有物品信息查询,登录信息验证,扫描登...
    方圆几度阅读 3,535评论 0 0
  • 没有面朝大海的房子 我们依然可以春暖花开 在喜欢多肉的姑娘眼里, 它们都是一只只可爱的小精灵。 面对街边门店里诱人...
    视青岛阅读 5,612评论 0 6
  • 终于,雨从铅色的天空飘落下来。大地在一片润意里静穆深深。 江南安稳的春意里,一阵低沉的马嘶远远地自街另一头传了过来...
    扑蝴蝶的大象阅读 2,338评论 0 0
  • 科三合场是完全没有底气的,我像一只无头苍蝇一样到处乱撞,结果是负了几百分。前一天晚上,我翻来覆去睡不着,想着即将到...
    峡溪飞瀑阅读 1,248评论 0 3