iOS 二维码扫描和成像,成像带小图标 自定义色值
来源:互联网 发布:2016淘宝排名权重因素 编辑:程序博客网 时间:2024/05/10 05:24
工具下载:http://download.csdn.net/detail/wsk_123_123/7177635
代码:
//// YYViewController.h// Dm//// Created by *** on 14-4-11.// Copyright (c) 2014年 **. All rights reserved.//#import <UIKit/UIKit.h>#import "ZBarSDK.h"#import <QuartzCore/QuartzCore.h>@interface YYViewController : UIViewController<ZBarReaderDelegate,UITextFieldDelegate>-(IBAction)btnyy:(id)sender;-(IBAction)btnsm:(id)sender;@end
//// YYViewController.m// Dm//// Created by ** on 14-4-11.// Copyright (c) 2014年 **. All rights reserved.//#import "YYViewController.h"#import "QRCodeGenerator.h"@interface YYViewController (){ IBOutlet UIButton *btnyy; IBOutlet UIImageView *img; IBOutlet UITextField *sd;}@end@implementation YYViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; sd.delegate=self; // Do any additional setup after loading the view from its nib.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}-(IBAction)btnsm:(id)sender{ /*扫描二维码部分: 导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framework libiconv.dylib 引入头文件#import “ZBarSDK.h” 即可使用 当找到条形码时,会执行代理方法 - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info 最后读取并显示了条形码的图片和内容。*/ [sd resignFirstResponder]; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){ ZBarReaderViewController *reader = [ZBarReaderViewController new]; reader.readerDelegate = self; reader.supportedOrientationsMask = ZBarOrientationMaskAll; ZBarImageScanner *scanner = reader.scanner; [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0]; [self presentModalViewController: reader animated: YES]; } else { UIAlertView *aler=[[UIAlertView alloc]initWithTitle:@"Message" message:@"无法打开设备的摄像头!请授权!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确认", nil]; [aler show]; } }- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info{ [sd resignFirstResponder]; id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults]; ZBarSymbol *symbol = nil; for(symbol in results) // EXAMPLE: just grab the first barcode break; // EXAMPLE: do something useful with the barcode data NSLog(@"%@",symbol.data); img.image = [info objectForKey: UIImagePickerControllerOriginalImage]; [reader dismissModalViewControllerAnimated: YES]; //判断是否包含 头'http:' NSString *regex = @"http+:[^\\s]*"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; //判断是否包含 头'ssid:' NSString *ssid = @"ssid+:[^\\s]*";; NSPredicate *ssidPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ssid]; sd.text = symbol.data ; if ([predicate evaluateWithObject:sd.text]) { UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:@"It will use the browser to this URL。" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:@"Ok", nil]; alert.delegate = self; alert.tag=1; [alert show]; } else if([ssidPre evaluateWithObject:sd.text]){ NSArray *arr = [sd.text componentsSeparatedByString:@";"]; NSArray * arrInfoHead = [[arr objectAtIndex:0] componentsSeparatedByString:@":"]; NSArray * arrInfoFoot = [[arr objectAtIndex:1] componentsSeparatedByString:@":"]; sd.text= [NSString stringWithFormat:@"ssid: %@ \n password:%@", [arrInfoHead objectAtIndex:1],[arrInfoFoot objectAtIndex:1]]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:sd.text message:@"The password is copied to the clipboard , it will be redirected to the network settings interface" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:@"Ok", nil]; alert.delegate = self; alert.tag=2; [alert show]; UIPasteboard *pasteboard=[UIPasteboard generalPasteboard]; // 然后,可以使用如下代码来把一个字符串放置到剪贴板上: pasteboard.string = [arrInfoFoot objectAtIndex:1]; } }-(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES;}-(IBAction)btnyy:(id)sender{ [sd resignFirstResponder]; UIImage *imgs=[UIImage imageNamed:@"1xx.png"]; img.image = [QRCodeGenerator qrImageForString:sd.text imageSize:img.bounds.size.width Topimg:imgs];// img.image= [QRCodeGenerator qrImageForString:sd.text imageSize:img.frame.size.width withPointType:0 withPositionType:0 withColor:[UIColor redColor]];}@end
0 0
- iOS 二维码扫描和成像,成像带小图标 自定义色值
- 二维码扫描和成像,成像带小图标 自定义色值
- 成像
- iOS自带扫描 和 生成二维码
- iOS自带扫描 和 生成二维码
- iOS自带扫描 和 生成二维码
- iOS自带扫描 和 生成二维码
- iOS自带扫描和生成二维码
- 原生二维码扫描实现, 二维码、中间带小图标、条形码生成
- IOS 中实现自定义扫描二维码和生成二维码
- TOF相机-非扫描三维成像
- CR和DR成像技术
- 彩色成像原理和vonK iies 色适应理论
- 幻影成像
- 红外成像
- 小孔成像
- IOS前置摄像头左右成像问题
- iOS视图成像理论及性能优化
- oracle 解锁
- 秒杀多线程第二篇 多线程第一次亲密接触 CreateThread与_beginthreadex本质区别
- mybatis多对一查询
- Hadoop 2.2 and Maven
- 为什么电脑很热?
- iOS 二维码扫描和成像,成像带小图标 自定义色值
- 如何使用css自动使得图片自己改变大小
- c语言绝对值符号
- 信息推送服务使用规则
- 第七周项目6-人数不定的工资类
- jsp
- region assign 流程补充说明
- 造成端口起不来的几种情况
- NYOJ65另一种阶乘问题