美文网首页
IOS-生成二维码

IOS-生成二维码

作者: 温学振 | 来源:发表于2017-10-09 15:04 被阅读31次

    生成二维码

     CIFilter *qrcodefilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
     [qrcodefilter setDefaults];  
     NSString *str = @"http://www.jianshu.com/u/51716bf1008a";
     NSData *data2 = [str dataUsingEncoding:NSUTF8StringEncoding];
     [qrcodefilter setValue:data2 forKey:@"inputMessage"];
     CIImage *outputImage = [qrcodefilter outputImage];
    

    二维码大小

    CGFloat qrcodescaleX = 120 / outputImage.extent.size.width; // extent 返回图片的frame
    CGFloat qrcodescaleY = 120 / outputImage.extent.size.height;
    

    压缩图片

    CIImage *tranImage = [outputImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, qrcodescaleX, qrcodescaleY)];
    UIImage *rcode_image=[UIImage imageWithCIImage:tranImage];
    

    重新赋值

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(HCSystemWidth *0.5 -50, 120, 100, 100)]; imageView.image = rcode_image;
    imageView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];

    相关文章

      网友评论

          本文标题:IOS-生成二维码

          本文链接:https://www.haomeiwen.com/subject/grhpyxtx.html