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
    
  • 相关阅读:
    PythonStudy——epoll 模块实现异步IO模型
    MySQLStudy——Mac下MySQL 允许用户远程访问数据库
    MySQLStudy——MySQL 基础语句
    MySQLStudy——MySQL 概念
    MySQLStudy——Mac下MySQL 常用命令 启动 关闭 重启服务 查看版本
    PythonStudy——IO模型
    PythonStudy——非阻塞IO模型
    PythonStudy——多路复用IO select实现
    restfull api
    斜体菜单
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5729336.html
Copyright © 2011-2022 走看看