zoukankan      html  css  js  c++  java
  • 用指定颜色生成指定尺寸的图片

    特别注意需要UIKit框架

    #import <UIKit/UIKit.h>
    
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    //需要UIKit框架
    @interface YFCreateImage : NSObject
    
    /**用指定颜色生成指定尺寸的图片*/
    -(UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size;
    
    @end
    #import "YFCreateImage.h"
    
    @implementation YFCreateImage
    /**用指定颜色生成指定尺寸的图片*/
    -(UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size
    {
        CGRect rect = CGRectMake(0.0f,0.0f,size.width,size.height);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context =UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        UIImage *myImage =UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return myImage;
    }
    @end

    也可以更换为下面方法使用

    +(UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size;
    

     

  • 相关阅读:
    Spring AOP 详解
    java 线程的几种状态
    Atomic
    ConcurrentHashMap原理分析
    MySQL存储过程详解 mysql 存储过程
    spring-定时器(2)
    spring-定时器(1)
    spring-线程池(3)
    spring-线程池(2)
    spring-线程池(1)
  • 原文地址:https://www.cnblogs.com/OIMM/p/9292675.html
Copyright © 2011-2022 走看看