关闭

二维码扫描和成像,成像带小图标 自定义色值

265人阅读 评论(0) 收藏 举报
分类:
  1. //  
  2. //  YYViewController.h  
  3. //  Dm  
  4. //  
  5. //  Created by *** on 14-4-11.  
  6. //  Copyright (c) 2014年 **. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10. #import "ZBarSDK.h"  
  11. #import <QuartzCore/QuartzCore.h>  
  12. @interface YYViewController : UIViewController<ZBarReaderDelegate,UITextFieldDelegate>  
  13.   
  14. -(IBAction)btnyy:(id)sender;  
  15. -(IBAction)btnsm:(id)sender;  
  16. @end  

[objc] view plaincopy在CODE上查看代码片派生到我的代码片
  1. //  
  2. //  YYViewController.m  
  3. //  Dm  
  4. //  
  5. //  Created by ** on 14-4-11.  
  6. //  Copyright (c) 2014年 **. All rights reserved.  
  7. //  
  8.   
  9. #import "YYViewController.h"  
  10. #import "QRCodeGenerator.h"  
  11.   
  12. @interface YYViewController ()  
  13. {  
  14.     IBOutlet UIButton *btnyy;  
  15.     IBOutlet UIImageView *img;  
  16.     IBOutlet UITextField *sd;  
  17. }  
  18. @end  
  19.   
  20. @implementation YYViewController  
  21.   
  22. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  23. {  
  24.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  25.     if (self) {  
  26.         // Custom initialization  
  27.     }  
  28.     return self;  
  29. }  
  30.   
  31. - (void)viewDidLoad  
  32. {  
  33.     [super viewDidLoad];  
  34.     sd.delegate=self;  
  35.     // Do any additional setup after loading the view from its nib.  
  36. }  
  37.   
  38. - (void)didReceiveMemoryWarning  
  39. {  
  40.     [super didReceiveMemoryWarning];  
  41.     // Dispose of any resources that can be recreated.  
  42. }  
  43. -(IBAction)btnsm:(id)sender  
  44. {  
  45.     /*扫描二维码部分: 
  46.      导入ZBarSDK文件并引入一下框架 
  47.      AVFoundation.framework 
  48.      CoreMedia.framework 
  49.      CoreVideo.framework 
  50.      QuartzCore.framework 
  51.      libiconv.dylib 
  52.      引入头文件#import “ZBarSDK.h” 即可使用 
  53.      当找到条形码时,会执行代理方法 
  54.       
  55.      - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info 
  56.       
  57.      最后读取并显示了条形码的图片和内容。*/  
  58.     [sd resignFirstResponder];  
  59.     if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){  
  60.     ZBarReaderViewController *reader = [ZBarReaderViewController new];  
  61.     reader.readerDelegate = self;  
  62.     reader.supportedOrientationsMask = ZBarOrientationMaskAll;  
  63.       
  64.     ZBarImageScanner *scanner = reader.scanner;  
  65.       
  66.     [scanner setSymbology: ZBAR_I25  
  67.                    config: ZBAR_CFG_ENABLE  
  68.                        to: 0];  
  69.       
  70.     [self presentModalViewController: reader  
  71.                             animated: YES];  
  72.     }  
  73.     else  
  74.     {  
  75.         UIAlertView *aler=[[UIAlertView alloc]initWithTitle:@"Message" message:@"无法打开设备的摄像头!请授权!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确认", nil nil];  
  76.         [aler show];  
  77.     }  
  78.    
  79.   
  80.       
  81. }  
  82. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  83. {  
  84.     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);  
  85. }  
  86. - (void) imagePickerController: (UIImagePickerController*) reader  
  87.  didFinishPickingMediaWithInfo: (NSDictionary*) info  
  88. {  
  89.       [sd resignFirstResponder];  
  90.     id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];  
  91.     ZBarSymbol *symbol = nil;  
  92.     for(symbol in results)  
  93.         // EXAMPLE: just grab the first barcode  
  94.         break;  
  95.       
  96.     // EXAMPLE: do something useful with the barcode data  
  97.     NSLog(@"%@",symbol.data);  
  98.       
  99.     img.image =  
  100.     [info objectForKey: UIImagePickerControllerOriginalImage];  
  101.       
  102.     [reader dismissModalViewControllerAnimated: YES];  
  103.       
  104.     //判断是否包含 头'http:'  
  105.     NSString *regex = @"http+:[^\\s]*";  
  106.     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];  
  107.       
  108.     //判断是否包含 头'ssid:'  
  109.     NSString *ssid = @"ssid+:[^\\s]*";;  
  110.     NSPredicate *ssidPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ssid];  
  111.       
  112.     sd.text =  symbol.data ;  
  113.       
  114.     if ([predicate evaluateWithObject:sd.text]) {  
  115.           
  116.         UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil  
  117.                                                         message:@"It will use the browser to this URL。"  
  118.                                                        delegate:nil  
  119.                                               cancelButtonTitle:@"Close"  
  120.                                               otherButtonTitles:@"Ok", nil nil];  
  121.         alert.delegate = self;  
  122.         alert.tag=1;  
  123.         [alert show];  
  124.    
  125.           
  126.     }  
  127.     else if([ssidPre evaluateWithObject:sd.text]){  
  128.           
  129.         NSArray *arr = [sd.text componentsSeparatedByString:@";"];  
  130.           
  131.         NSArray * arrInfoHead = [[arr objectAtIndex:0] componentsSeparatedByString:@":"];  
  132.           
  133.         NSArray * arrInfoFoot = [[arr objectAtIndex:1] componentsSeparatedByString:@":"];  
  134.           
  135.           
  136.         sd.text=  
  137.         [NSString stringWithFormat:@"ssid: %@ \n password:%@",  
  138.          [arrInfoHead objectAtIndex:1],[arrInfoFoot objectAtIndex:1]];  
  139.           
  140.           
  141.         UIAlertView * alert = [[UIAlertView alloc]initWithTitle:sd.text  
  142.                                                         message:@"The password is copied to the clipboard , it will be redirected to the network settings interface"  
  143.                                                        delegate:nil  
  144.                                               cancelButtonTitle:@"Close"  
  145.                                               otherButtonTitles:@"Ok", nil nil];  
  146.           
  147.           
  148.         alert.delegate = self;  
  149.         alert.tag=2;  
  150.         [alert show];  
  151.    
  152.         UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];  
  153.         //        然后,可以使用如下代码来把一个字符串放置到剪贴板上:  
  154.         pasteboard.string = [arrInfoFoot objectAtIndex:1];  
  155.           
  156.           
  157.     }  
  158.       
  159. }  
  160. -(BOOL)textFieldShouldReturn:(UITextField *)textField  
  161. {  
  162.     [textField resignFirstResponder];  
  163.     return YES;  
  164. }  
  165. -(IBAction)btnyy:(id)sender  
  166. {  
  167.     [sd resignFirstResponder];  
  168.     UIImage *imgs=[UIImage imageNamed:@"1xx.png"];  
  169.     img.image = [QRCodeGenerator qrImageForString:sd.text imageSize:img.bounds.size.width Topimg:imgs];  
  170. //    img.image= [QRCodeGenerator  qrImageForString:sd.text imageSize:img.frame.size.width withPointType:0 withPositionType:0 withColor:[UIColor redColor]];  
  171. }  
  172.   
  173. @end  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:7533次
    • 积分:449
    • 等级:
    • 排名:千里之外
    • 原创:39篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档