ios sdk二维码生成器
2016-06-19 16:27
453 查看
//二维码生成且放到UIImageView显示
- (void)ciImageFromString:(NSString *)qrString imgView:(UIImageView *)imgView imgSize:(CGSize)size{
imgView.backgroundColor = [UIColor redColor];
imgView.contentMode = UIViewContentModeCenter;
NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding];
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[filter setValue:stringData forKey:@"inputMessage"];
// 5.生成二维码
CIImage *outputImage = filter.outputImage;
CGFloat scale = size.width / CGRectGetWidth(outputImage.extent);
CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale); // scale 为放大倍数
CIImage *transformImage = [outputImage imageByApplyingTransform:transform];
// 保存
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [context createCGImage:transformImage fromRect:transformImage.extent];
UIImage *qrCodeImage = [UIImage imageWithCGImage:imageRef];
// 6.设置生成好得二维码到imageView上
imgView.image = qrCodeImage;
}
- (void)ciImageFromString:(NSString *)qrString imgView:(UIImageView *)imgView imgSize:(CGSize)size{
imgView.backgroundColor = [UIColor redColor];
imgView.contentMode = UIViewContentModeCenter;
NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding];
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[filter setValue:stringData forKey:@"inputMessage"];
// 5.生成二维码
CIImage *outputImage = filter.outputImage;
CGFloat scale = size.width / CGRectGetWidth(outputImage.extent);
CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale); // scale 为放大倍数
CIImage *transformImage = [outputImage imageByApplyingTransform:transform];
// 保存
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [context createCGImage:transformImage fromRect:transformImage.extent];
UIImage *qrCodeImage = [UIImage imageWithCGImage:imageRef];
// 6.设置生成好得二维码到imageView上
imgView.image = qrCodeImage;
}
相关文章推荐
- iOS使用半透明模糊效果方法整理
- IOS SDK图片二维码识别
- [置顶] iOS开发—单元测试
- iOS真机测试碰到错误linker command failed with exit code 1 (use -v to see invocation)
- iOS9新特性
- ios 事件穿透
- ios计算函数的执行时长
- IOS性能调优系列:使用Time Profiler发现性能瓶颈
- 如何安装 CocoaPods并打开开源中国IOS
- IOS性能调优系列:使用Zombies动态分析内存中的僵尸对象
- ios多线程
- iOS中使用MD5加密字符串
- iOS真机测试could not find developer disk image
- 【Ionic实战】一个和AngularJS的跨平台(iOS,Android) APP框架
- iOS开发:关于IPV6
- iOS9 3DTouch、ShortcutItem、Peek And Pop技术一览
- ios学习路线—静态变量,全局变量exterm,局部变量,实例变量
- 在Visual Studio 2010/2012/2013/2015上使用C#开发Android/IOS安装包和操作步骤
- iOS 加密
- iOS图片上传及压缩