iOS 根据url生成高清二维码


生成高清二维码:

   self.CodeImageView = [UIImageView new];

    [scannWhiteView addSubview:self.CodeImageView];

    [self.CodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {

       

        make.top.equalTo(bgView.mas_bottom).offset(10);

        make.bottom.equalTo(scannWhiteView).offset (-40);

        make.left.equalTo(scannWhiteView).offset (42);

        make.right.equalTo(scannWhiteView).offset (-42);

        

    }];


    //生成二维码

    // 1. 创建一个二维码滤镜实例(CIFilter)

    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

    // 滤镜恢复默认设置

    [filter setDefaults];


    // 2. 给滤镜添加数据

    NSString *string = self.codeUrl;  //加入二维码url

    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];

    [filter setValue:data forKeyPath:@"inputMessage"];


    // 3. 生成高清二维码

    CIImage *image = [filter outputImage];

    CGAffineTransform transform = CGAffineTransformMakeScale(5.0f, 5.0f);

    CIImage *output = [image imageByApplyingTransform: transform];

    UIImage *newImage = [UIImage imageWithCIImage:output scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];

    // 4. 显示二维码

    self.CodeImageView.image = newImage;

    



你可能感兴趣的:(iOS移动开发)