zoukankan      html  css  js  c++  java
  • 通过颜色生成图片

    /**
     *  通过颜色生成纯颜色的图片
     */
    
    #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"
    #import "UIImage+CreatImageWithColor.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
    //    UIImage *image = [UIImage imageWithColor:[UIColor redColor] imageWidth:100 imageWithHeight:100];
        UIImage *image = [UIImage imageWithColor:[UIColor yellowColor]];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(100, 100, 200, 200);
        [self.view addSubview:imageView];
    }
    
    
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface UIImage (CreatImageWithColor)
    
    /**
     *  通过颜色生成该纯颜色的图片
     *
     *  @param color 生成图片的颜色
     *
     *  @return 返回图片
     */
    + (UIImage *)imageWithColor:(UIColor *)color;
    
    /**
     *  通过颜色生成该纯颜色的图片
     *
     *  @param color  生成图片的颜色
     *  @param width  生成图片的宽
     *  @param height 生成图片的高
     *
     *  @return 返回图片
     */
    + (UIImage *)imageWithColor:(UIColor *)color imageWidth:(CGFloat)width imageWithHeight:(CGFloat)height;
    
    @end
    #import "UIImage+CreatImageWithColor.h"
    
    @implementation UIImage (CreatImageWithColor)
    
    + (UIImage *)imageWithColor:(UIColor *)color{
        return [UIImage imageWithColor:color imageWidth:100 imageWithHeight:100];
    }
    
    + (UIImage *)imageWithColor:(UIColor *)color imageWidth:(CGFloat)width imageWithHeight:(CGFloat)height{
        
        //开启基于位图的图形上下文
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(width,height), NO, 0.0);
        // 设置画笔的颜色
        [color set];
        // 画矩形,并填充
        UIRectFill(CGRectMake(0, 0, width, height));
        //获取图片
        UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
        //关闭上下文
        UIGraphicsEndImageContext();
        
        return resultImage;
    }
    
    @end
  • 相关阅读:
    cube.js 基于http 通道的数据实时更新bug 解决
    cube.js 基于http 通道的数据实时更新
    cube.js websocket 实时数据更新说明
    phpspy 进行php 项目性能分析
    使用groovy 下载maven依赖包
    java 几个不错的代码生成工具
    语言性能分析工具总结
    使用rbspy 分析ruby应该性能
    dremio v18.0 软件包可以使用了
    nginx rewrite查询字符串重写问题
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5453269.html
Copyright © 2011-2022 走看看