亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS二維碼的生成和掃描

 更新時(shí)間:2017年03月01日 14:02:15   作者:唐宋元明清。  
這篇文章主要為大家詳細(xì)介紹了iOS二維碼生成和掃描的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下

屬性

@property (strong,nonatomic)AVCaptureDevice * device;
@property (strong,nonatomic)AVCaptureDeviceInput * input;
@property (strong,nonatomic)AVCaptureMetadataOutput * output;
@property (strong,nonatomic)AVCaptureSession * session;
@property (strong,nonatomic)AVCaptureVideoPreviewLayer * layer; 
@property (nonatomic, strong)UIImageView *imageView;

二維碼的生成

// 1.創(chuàng)建過濾器
  CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
 
  // 2.恢復(fù)默認(rèn)
  [filter setDefaults];
 
  // 3.給過濾器添加數(shù)據(jù)(正則表達(dá)式/賬號(hào)和密碼)
  NSString *dataString = @"http://www.520it.com";
  NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
  [filter setValue:data forKeyPath:@"inputMessage"];
 
  // 4.獲取輸出的二維碼
  CIImage *outputImage = [filter outputImage];
 
  //因?yàn)樯傻亩S碼模糊,所以通過createNonInterpolatedUIImageFormCIImage:outputImage來(lái)獲得高清的二維碼圖片
 
  // 5.顯示二維碼
  self.imageView.image = [self createNonInterpolatedUIImageFormCIImage:outputImage withSize:200];

 * createNonInterpolatedUIImageFormCIImage:outputImage方法的實(shí)現(xiàn)

/**
 * 根據(jù)CIImage生成指定大小的UIImage
 *
 * @param image CIImage
 * @param size 圖片寬度
 */
- (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size
{
  CGRect extent = CGRectIntegral(image.extent);
  CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
 
  // 1.創(chuàng)建bitmap;
  size_t width = CGRectGetWidth(extent) * scale;
  size_t height = CGRectGetHeight(extent) * scale;
  CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
  CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
  CIContext *context = [CIContext contextWithOptions:nil];
  CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
  CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
  CGContextScaleCTM(bitmapRef, scale, scale);
  CGContextDrawImage(bitmapRef, extent, bitmapImage);
 
  // 2.保存bitmap到圖片
  CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
  CGContextRelease(bitmapRef);
  CGImageRelease(bitmapImage);
  return [UIImage imageWithCGImage:scaledImage];
}

 二維碼的掃描

// 1.創(chuàng)建捕捉會(huì)話
  AVCaptureSession *session = [[AVCaptureSession alloc] init];
  self.session = session;
 
  // 2.添加輸入設(shè)備(數(shù)據(jù)從攝像頭輸入)
  AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
  [session addInput:input];
 
  // 3.添加輸出數(shù)據(jù)(示例對(duì)象-->類對(duì)象-->元類對(duì)象-->根元類對(duì)象)
  AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
  [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
  [session addOutput:output];
 
  // 3.1.設(shè)置輸入元數(shù)據(jù)的類型(類型是二維碼數(shù)據(jù))
  [output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];
 
  // 4.添加掃描圖層
  AVCaptureVideoPreviewLayer *layer = [AVCaptureVideoPreviewLayer layerWithSession:session];
  layer.frame = self.view.bounds;
  [self.view.layer addSublayer:layer];
  self.layer = layer;
 
  // 5.開始掃描
  [session startRunning];

 *掃描到結(jié)果后會(huì)調(diào)用的方法

// 當(dāng)掃描到數(shù)據(jù)時(shí)就會(huì)執(zhí)行該方法
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
  if (metadataObjects.count > 0) {
    //獲得掃描數(shù)據(jù),最后一個(gè)時(shí)最新掃描的數(shù)據(jù)
    AVMetadataMachineReadableCodeObject *object = [metadataObjects lastObject];
    NSLog(@"%@", object.stringValue);
 
    // 停止掃描
    [self.session stopRunning];
 
    // 將預(yù)覽圖層移除
    [self.layer removeFromSuperlayer];
  } else {
    NSLog(@"沒有掃描到數(shù)據(jù)");
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • ios NSNotificationCenter通知的簡(jiǎn)單使用

    ios NSNotificationCenter通知的簡(jiǎn)單使用

    這篇文章主要介紹了ios NSNotificationCenter通知的簡(jiǎn)單使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-06-06
  • iOS中表單列表樣式鍵盤遮擋的解決方案

    iOS中表單列表樣式鍵盤遮擋的解決方案

    這篇文章主要給大家介紹了關(guān)于iOS中表單列表樣式鍵盤遮擋的解決方案,文中通過示例代碼將解決的方法一步步介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧
    2019-01-01
  • iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵

    這篇文章主要介紹了iOS開發(fā)之UIKeyboardTypeNumberPad數(shù)字鍵盤自定義按鍵 的相關(guān)資料,需要的朋友可以參考下
    2016-08-08
  • iOS如何為圓角添加陰影效果示例代碼

    iOS如何為圓角添加陰影效果示例代碼

    最近一個(gè)項(xiàng)目中需要用到投影的效果,還要是圓角,通過查找相關(guān)的資料終于解決了,所以覺著有必要分享出來(lái),下面這篇文章主要給大家介紹了關(guān)于iOS如何為圓角添加陰影效果的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-10-10
  • iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式

    iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式

    在本文里我們給大家分享了關(guān)于iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的讀者們可以參考下。
    2019-05-05
  • 全面解析iOS應(yīng)用中自定義UITableViewCell的方法

    全面解析iOS應(yīng)用中自定義UITableViewCell的方法

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中自定義UITableViewCell的方法,示例為傳統(tǒng)的Obejective-C語(yǔ)言,需要的朋友可以參考下
    2016-04-04
  • 詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    這篇文章主要介紹了詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • iOS定時(shí)器的選擇CADisplayLink NSTimer和GCD使用

    iOS定時(shí)器的選擇CADisplayLink NSTimer和GCD使用

    這篇文章主要為大家介紹了iOS定時(shí)器的選擇CADisplayLink NSTimer和GCD使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • iOS開發(fā)定時(shí)器的三種方法分享

    iOS開發(fā)定時(shí)器的三種方法分享

    相信在大家開發(fā)過程中,常常需要在某個(gè)時(shí)間后執(zhí)行某個(gè)方法,或者是按照某個(gè)周期一直執(zhí)行某個(gè)方法。在這個(gè)時(shí)候,我們就需要用到定時(shí)器。然而,在iOS中有很多方法完成以上的任務(wù),到底有多少種方法呢?下面就通過這篇文章來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2016-09-09
  • iOS中的類、元類以及isa示例詳解

    iOS中的類、元類以及isa示例詳解

    從初學(xué)OC的時(shí)候就聽人提起過OC對(duì)象中的isa指針,用來(lái)指向?qū)ο笏鶎俚念?,從而可以在調(diào)用方法時(shí)通過isa指針找到相應(yīng)的方法和屬性,下面這篇文章主要給大家介紹了關(guān)于iOS中類、元類以及isa的相關(guān)資料,需要的朋友可以參考借鑒,下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01

最新評(píng)論