UIImage与UIColor互转
Objective-C
UIColor -> UIImage
|
1
2
3
4
5
6
7
8
9
10
11
|
- (UIImage*) createImageWithColor: (UIColor*) color{ CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage;} |
UIImage -> UIColor
|
1
|
[UIColor colorWithPatternImage:[UIImageimageNamed:@"Background"]] |
Swift
UIColor -> UIImage
|
1
2
3
4
5
6
7
8
9
10
11
|
func createImageWithColor(color: UIColor) -> UIImage{ let rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f) UIGraphicsBeginImageContext(rect.size) let context = UIGraphicsGetCurrentContext() CGContextSetFillColorWithColor(context, color.CGColor) CGContextFillRect(context, rect) let theImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return theImage} |
UIImage -> UIColor
|
1
|
UIColor(PatternImage: UIImage(named: @"Background")) |
UIImage与UIColor互转的更多相关文章
- 【代码笔记】iOS-16进制颜色与UIColor互转
一,效果图 二,工程目录. 三,代码 RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additio ...
- UIImage转换UIColor内存会莫名增大可以试试另一种方法
一般我们会用此方法加载被背景图片 [self.view setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc]initWi ...
- iOS 将UIColor转换为UIImage
/** * 将UIColor变换为UIImage * **/+ (UIImage *)createImageWithColor:(UIColor *)color{ CGRect rect = CGRe ...
- 通过UIColor转换为UIImage
+ (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); ...
- github源码学习之UIImage+YYWebImage
UIImage+YYWebImage是YYWebImage(https://github.com/ibireme/YYWebImage)中的一个分类,这个分类封装了一些image常用的变化方法,非常值 ...
- 改变图片的颜色,UIImage改变颜色
定义 #import <UIKit/UIKit.h> @interface UIImage (ChangeImageColor) /** * 改变图片的颜色 * * @param tint ...
- 利用颜色生成UIImage
// 颜色转换为背景图片 + (UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1. ...
- iOS开发-UIColor转UIIamge方法
只能说太神奇了,完美应用到我的毕业设计 - (UIImage*) createImageWithColor: (UIColor*) color { CGRect rect=CGRectMake(,,s ...
- UIImage图片处理,旋转、截取、平铺、缩放等操作
来源:iOS_小松哥 链接:http://www.jianshu.com/p/9ab1205f5166 有时候我们需要处理图片,比如改变大小,旋转,截取等等,所以今天说一说图片处理相关的一些操作. 本 ...
随机推荐
- 原生 javascript 学习之 js变量
1.变量的命名 方法的命名(驼峰命名法) 全部小写 : 单词与单词之间全部下划线 (my_namespace) 大小写混合 : 第一个单词首字母小写其他单词首字母大写. 规则 首字符 英文字母或下划线 ...
- oracle以web方式登录EM、ISQLPlus
1. 检查主机名/IP.端口安装时的主机名/IP.端口记录在$ORACLE_HOME/install/portlist.ini 文件中.缺省是:一般用户 htt ...
- [jQuery] 使用jQuery printPage plugin打印其他頁面內容
目標: 點選按鈕後可以打印其他頁面的內容,可用於套版.內部表單套印...等等. 程式碼: 1.View(HTML布局) <h2>維修申請單</h2> <form id=& ...
- AspNetPager
AspNetPager使用方法引入dll <%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer& ...
- .net文件下载方法汇总
转载自:http://blog.sina.com.cn/s/blog_680942070101ahsq.html //TransmitFile实现下载 protected void Button1_C ...
- UIImageView填充模式(contentMode)
UIViewContentModeScaleToFill :拉伸填充UIImageView满屏 UIViewContentModeScaleAspectFit :拉伸到合适UIIma ...
- CAS单点登录原理以及debug跟踪登录流程
CAS 原理和协议 基础模式 基础模式 SSO 访问流程主要有以下步骤: 1. 访问服务: SSO 客户端发送请求访问应用系统提供的服务资源. 2. 定向认证: SSO 客户端会重定向用户请求到 SS ...
- Codeforces Round #302 (Div. 1)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud A. Writing Code Programmers working on a ...
- 引用 exit、return、_exit、_Exit这几个函数的区别
引用 exit.return._exit._Exit这几个函数的区别 一.exit函数和return函数的主要区别是: exit用于在程序运行的过程中随时结束程序,其参数是返回给OS的.也可以这么讲: ...
- open_basedir restriction in effect. File() is not within the allowed path(s)
目前发现eaccelerator安装之后如果php.ini中设置open_basedir将导致open_basedir的一些报错(open_basedir restriction in effect. ...