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 有时候我们需要处理图片,比如改变大小,旋转,截取等等,所以今天说一说图片处理相关的一些操作. 本 ...
随机推荐
- myeclipse自动补全设置
第一步: windows -->preference -->java -->editor -->content Assist --> auto activation -- ...
- Node.js 之 express 入门 ejs include公共部分
1. 直接进入express安装 因为之前有一篇文章我已经讲过怎么安装node了 而网上的教程也是非常多.所有直接进入到express.教程简陋 由于我比较笨 所有只要写到我自己明白就行. 这里有个教 ...
- (转)sql中 in 、not in 、exists、not exists 用法和差别
exists (sql 返回结果集为真) not exists (sql 不返回结果集为真) 如下: 表A ID NAME 1 A1 2 A2 3 A3 表B ID AI ...
- linux 虚拟机centos64位_6.5+VM10 主机是固定IP局域网设置代理上网,虚机设置固定ip 图文详细步骤
一种: 虚机是Desktop 安装 1.虚拟机—设置—网络适配器子选项—选择“桥接模式” 2.在虚拟机中选择系统(System)—首选项(Preferences)—网络连接(Network Conne ...
- dug
http://blog.csdn.net/ysy441088327/article/details/8992393 http://www.cnblogs.com/Leo_wl/p/4423922.ht ...
- 定义block块
一: 工程图 二: 代码区 AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <U ...
- 再入门JavaScript
从去年毕业到现今,工作不到一年.接触了3个实际项目,一个实训项目.却反而只有实训项目做的比较像样子. 重新又回到写脚本的岗位上,第一次真正意义上接触脚本应该是在达内培训时候李大神所引进,大神各种技术, ...
- Java Se 基础系列(笔记) -- BasicDataType
java.lang.String类代表不可变的字符序列 String类常用方法:1.public char charAt(int index); -- 返回下标为index的字符 2.public i ...
- windows下配置svn的https访问
svn是一个功能强大的代码版本管理系统,可以将服务端安装在linux.unix以及windows下.svn通常采用http方式进行代码提交与下载.由于密码采用明文传输,因此存在泄密的风险.若采用htt ...
- 数据链路层-点对点协议PPP
在通信质量较差的年代,在数据链路层使用可靠传输协议曾是一个好的办法.因此,能实现可靠传输的高级数据链路控制HDLC(High-Level Data Link Control)就称为当时比较流行的数据链 ...