iOS-oc-二维码生成(带图片logo)

- (void)createLogoImage {
    NSArray *filter = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];
    NSLog(@"%@", filter);
    // 二维码过滤器
    CIFilter *filterImage = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    // 将二位码过滤器设置为默认属性
    [filterImage setDefaults];
    // 将文字转化为二进制
    NSData *dataImage = [@"http://www.baidu.com" dataUsingEncoding:NSUTF8StringEncoding];
    // 打印输入的属性
    NSLog(@"%@", filterImage.inputKeys);
    // KVC 赋值
    [filterImage setValue:dataImage forKey:@"inputMessage"];
    // 取出输出图片
    CIImage *outputImage = [filterImage outputImage];
    outputImage = [outputImage imageByApplyingTransform:CGAffineTransformMakeScale(20, 20)];
    // 转化图片
    UIImage *image = [UIImage imageWithCIImage:outputImage];

    // 为二维码加自定义图片

    // 开启绘图, 获取图片 上下文<图片大小>
    UIGraphicsBeginImageContext(image.size);
    // 将二维码图片画上去
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    // 将小图片画上去
    UIImage *smallImage = [UIImage imageNamed:@"taskAddImg"];
    [smallImage drawInRect:CGRectMake((image.size.width - 100) / 2, (image.size.width - 100) / 2, 100, 100)];
    // 获取最终的图片
    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
    // 关闭上下文
    UIGraphicsEndImageContext();
    // 显示
    self.imageView.image = finalImage;
}

你可能感兴趣的:(iOS-oc-二维码生成(带图片logo))