zoukankan      html  css  js  c++  java
  • ios--二维码生成

    二维码扫描

    • 使用ios的CIFilter框架实现二维码生成
    //生成二维码
    -(void)setupScan{
        CIFilter *filter=[CIFilter filterWithName:@"CIQRCodeGenerator"];
        [filter setDefaults];
        NSString *urlstr=@"http://www.ychpay.com/down.html";
        NSData *data=[urlstr dataUsingEncoding:NSUTF8StringEncoding];
        [filter setValue:data forKey:@"inputMessage"];
        CIImage *outputImage=[filter outputImage];
        UIImageView *wechatImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        wechatImageView.image=[self createNonInterpolatedUIImageFormCIImage:outputImage withSize:200];
        [self.view addSubview:wechatImageView];
        
    }
    - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size
    {
        CGRect extent = CGRectIntegral(image.extent);
        CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
        // 1.创建bitmap;
        size_t width = CGRectGetWidth(extent) * scale;
        size_t height = CGRectGetHeight(extent) * scale;
        CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
        CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
        CIContext *context = [CIContext contextWithOptions:nil];
        CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
        CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
        CGContextScaleCTM(bitmapRef, scale, scale);
        CGContextDrawImage(bitmapRef, extent, bitmapImage);
        // 2.保存bitmap到图片
        CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
        CGContextRelease(bitmapRef);
        CGImageRelease(bitmapImage);
        return [UIImage imageWithCGImage:scaledImage];
    }
    
  • 相关阅读:
    .bash_profile与.bashrc和.profile的区分概念
    java创建文件和目录
    Win7设置wifi热点
    JAVA之File类创建对象构造函数传参数需要注意的几点
    linux 控制台使用技巧
    poj1426-Find The Multiple
    Ubuntu下安装Android SDK(图文教程)
    屏蔽EditText长按导致的弹出输入法的对话框
    ZJUT 1423 地下迷宫(期望DP&高斯消元)
    Hadoop之SequenceFile
  • 原文地址:https://www.cnblogs.com/frankltf/p/7389127.html
Copyright © 2011-2022 走看看