生成二维码
//创建滤镜
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
//设置属性为默认值
[filter setDefaults];
//设置内容
[filter setValue:[@"https://itunes.apple.com/cn/app/招商全能王/id1153952115?mt=8" dataUsingEncoding:NSUTF8StringEncoding] forKey:@"inputMessage"];
CIImage *image = [filter outputImage];
image = [image imageByApplyingTransform:CGAffineTransformMakeScale(8, 8)];
这个image是保存不到相册的,需要绘制一下
绘制图片和保存到相册中
UIImage *newImage = [UIImage imageWithCIImage:image];
UIGraphicsBeginImageContext(newImage.size);
// 绘制二维码图片
[newImage drawInRect:CGRectMake(0, 0, newImage.size.width, newImage.size.height)];
// 从图片上下文中取出图片
newImage = UIGraphicsGetImageFromCurrentImageContext();
// 关闭图片上下文
UIGraphicsEndImageContext();
//保存图片到相册
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, NULL);