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

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    
    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        self.window.rootViewController = [[RootViewController alloc] init];
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    
    @end
    
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end
    
    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @property (nonatomic , strong) UIImageView *imgView;
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        CGFloat width = 200;
        CGFloat height = 200;
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.center.x - width/2.0, self.view.center.y - height/2.0, width, height)];
        [self.view addSubview:self.imgView];
        
        [self productImageView];
    }
    
    - (void)productImageView{
        
        CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
        
        [filter setDefaults];
        NSString *string = @"想择一人,一城;终老";
        NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
        [filter setValue:data forKey:@"inputMessage"];
        CIImage *outputImage = [filter outputImage];
        
        self.imgView.image = [self createUIImageFromCIImage:outputImage withSize:100.0];
    }
    
    - (UIImage *)createUIImageFromCIImage:(CIImage *)image withSize:(CGFloat)size{
        CGRect extent = CGRectIntegral(image.extent);
        CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
        
        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);
        
        CGImageRef scaleImage = CGBitmapContextCreateImage(bitmapRef);
        
        CGContextRelease(bitmapRef);
        
        CGImageRelease(bitmapImage);
        
        return [UIImage imageWithCGImage:scaleImage];
    }
    
    
    
    @end
    
  • 相关阅读:
    4-8(十五)性能测试流程
    数据库面试题(一)多表查询
    4-8(十四) jmeter 性能分析从哪几个方面
    4-8(十二)Jmeter+Ant+Jenkins定时构建
    4-8(十一)Jmeter自动化集成工具Ant的安装
    4-8(十)Jmeter 分布式测试
    4-8(九)Jmeter性能测试之阶梯式场景(负载测试)、波浪式场景(压力测试)
    4-8(八)Jmeter性能测试插件jpgc的安装
    4-8(六)Jmeter 脚本录制后调优
    6分钟演示,15种排序算法(视频)
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5729336.html
Copyright © 2011-2022 走看看