生成二维码
2015-12-23 15:07
387 查看
为什么没和条形码一起写?是因为之前项目中都用到了,但是并不是从一个地方寻找到的方法,并且之前的条形码方法是传入宽高和内容直接返回的图片,这个二维码的方法是传入已经建立好的UIImageView和二维码内容与清晰度获得一个二维码。
//调用生成方法(参数1.UIImageView 参数2.二维码内容 参数3.清晰度Scale数值越高越清晰)
[self barImageWithImageView:imageView String:@"http://www.baidu.com"Scale:4];
//生成方法
感谢观看,学以致用更感谢!
//调用生成方法(参数1.UIImageView 参数2.二维码内容 参数3.清晰度Scale数值越高越清晰)
[self barImageWithImageView:imageView String:@"http://www.baidu.com"Scale:4];
//生成方法
- (void)barImageWithImageView:(UIImageView*)imageView String:(NSString*)str Scale:(CGFloat)scale{ CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; [filter setDefaults]; NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; [filter setValue:data forKey:@"inputMessage"]; CIImage *outputImage = [filter outputImage]; CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]]; UIImage *image = [UIImage imageWithCGImage:cgImage scale:1.0 orientation:UIImageOrientationUp]; UIImage *resized =nil; CGFloat width = image.size.width*scale; CGFloat height = image.size.height*scale; UIGraphicsBeginImageContext(CGSizeMake(width, height)); CGContextRef context1 =UIGraphicsGetCurrentContext(); CGContextSetInterpolationQuality(context1,kCGInterpolationNone); [image drawInRect:CGRectMake(0,0, width, height)]; resized = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); imageView.image = resized; CGImageRelease(cgImage); }
感谢观看,学以致用更感谢!
相关文章推荐
- 运行/etc/init.d/ser_app restart,出现Terminated提示,进程起不来
- iOS判断字符串是否包含空格
- php,c# hamsha1
- 设计模式C++实现--职责链模式
- mysql查询语句in和exists二者的区别和性能影响
- POJ1159 Palindrome 动态规划+滚动数组
- JS实现瀑布流
- 拜将坛
- 基于ajaxFileUpload的文件上传插件(修复onchange第二次失效)
- sed 删除行首空格
- [AngularJS] Simple Data Binding
- JPA之Entity注解说明
- 设计模式C++实现--中介者模式
- 绑定数据时。在后台给GridView添加事件
- C#异步编程的实现方式——ThreadPool线程池
- 使用UML画类图
- 你还需要除PHP之外的编程语言吗(1)
- 第七章 -----与WEB集成
- udp如何实现可靠性传输?
- 机器学习中的偏差和方差