• 【IOS】集成zxing(二维码扫描)


    现在zxing已经到了2.2版本,以前的集成方式出了点问题。下面我做出一点修正。
    以前的版本的集成方法,参考:http://blog.devtang.com/blog/2012/12/23/use-zxing-library/
    按照以前的方式做好后  然后就是适配以下现在的版本的修改
    1.增加   SenTestingKit  框架 设置为Optional
    2.把目录 iphone/ZXingWidget 下的Tests删了
    3.保留目录 cpp/core/src 的bigint文件
    最后提醒:  设置查找路径时应该选择  User Header Search Paths 选项添加查找路径
    保险一点把  Always Search User Paths  选为Yes 这样就可以了

    还有就是要支持ios4.3的话就要设置一下C++Standard Library  为  libstdc++  这样就可以支持4.3的版本 

    在线生成二维码的网站:http://cli.im/ 
     
     【拓展:特定区域扫描】
    二维码扫描处理过程:
    程序有一个回调方法获取屏幕图片,然后进行解析。扫描会不断获取屏幕图片去解析。

    自定义扫描区域思路:
    只要我们在回调方法里面将获取的整个屏幕图片截取某一个区域,就可以实现特定区域扫描功能

     1 //回调方法
     2 - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
     3 {
     4   // 第一步,将sampleBuffer转成UIImage 
     5     UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
     6     // 第二步,用Decoder识别图象
     7     [self decodeImage:image];
     8 }
     9 
    10 #pragma mark - 截取图片
    11 
    12 - (void)cutMapView:(UIView *)theView
    13 
    14 {
    15 
    16 //************** 得到图片 *******************
    17 
    18 CGRect rect = theView.frame; //截取图片大小
    19 
    20  
    21 
    22 //开始取图,参数:截图图片大小
    23 
    24 UIGraphicsBeginImageContext(rect.size);
    25 
    26 //截图层放入上下文中
    27 
    28 [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    29 
    30 //从上下文中获得图片
    31 
    32 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    33 
    34 //结束截图
    35 
    36 UIGraphicsEndImageContext();
    37 
    38  
    39 
    40  
    41 
    42 //************** 存图片 *******************
    43 
    44 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    45 
    46 NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu"]]; // 保存文件的名称
    47 
    48 NSLog(@"filePath = %@",filePath);
    49 
    50 //UIImagePNGRepresentation方法将image对象转为NSData对象
    51 
    52 //写入文件中
    53 
    54 BOOL result = [UIImagePNGRepresentation(image)writeToFile: filePath atomically:YES];
    55 
    56 NSLog(@"result = %d",result);
    57 
    58  
    59 
    60  
    61 
    62 //*************** 截取小图 ******************
    63 
    64 CGRect rect1 = CGRectMake(90, 0, 82, 82);//创建矩形框
    65 
    66 //对图片进行截取
    67 
    68 UIImage * image2 = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([image CGImage], rect1)];
    69 
    70 NSString *filePath2 = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu2"]]; // 保存文件的名称
    71 
    72 NSLog(@"filePath = %@",filePath);
    73 
    74 BOOL result2 = [UIImagePNGRepresentation(image2)writeToFile:filePath2 atomically:YES];
    75 
    76 NSLog(@"result2 = %d",result2);
    77 
    78  
    79 
    80 //存入相册
    81 
    82 //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    83 
    84 }
    85 
    86 
    87 //截取图片特定区域
    88 /**
    89 *从图片中按指定的位置大小截取图片的一部分
    90 * UIImage image 原始的图片
    91 * CGRect rect 要截取的区域
    92 */
    93 - (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect {    
    94     CGImageRef sourceImageRef = [image CGImage];    
    95     CGImageRef newImageRef =     CGImageCreateWithImageInRect(sourceImageRef, rect);    
    96     UIImage *newImage = [UIImage imageWithCGImage:newImageRef];    
    97     return newImage;    
    98 }
  • 相关阅读:
    CF1324F Maximum White Subtree(树形dp)
    定时任务集群部署
    zookeeper服务的注册与发现
    多个定时任务服务注册到zookeeper临时顺序节点配置
    nginx反向代理
    nginx反向代理、负载均衡
    Eclipse快捷键
    下拉列表中复选框多选
    Zookeeper节点查看工具
    git打tag
  • 原文地址:https://www.cnblogs.com/DannyApple/p/3940516.html
Copyright © 2020-2023  润新知