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 有时候我们需要处理图片,比如改变大小,旋转,截取等等,所以今天说一说图片处理相关的一些操作. 本 ...
随机推荐
- Gunplot 命令大全
在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. plot命令 gnuplot> plot sin(x) with line linetype 3 linew ...
- js点击打开弹窗
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- (转)javascript组件开发方式
作为一名前端工程师,写组件的能力至关重要.虽然javascript经常被人嘲笑是个小玩具,但是在一代代大牛的前仆后继的努力下,渐渐的也摸索了一套组件的编写方式. 下面我们来谈谈,在现有的知识体系下,如 ...
- vs2015体验
项目结构 bower.json Bower依据此文件安装需要的前端的包 package.json NPM依据此文件获取对应的包 project.json 包含用于NPM的"poststore ...
- FineUI页面布局
使用布局的优势 相对于为控件设置固定的宽度和高度,布局的重要意义在于子控件可以根据父控件的尺寸自动设置自己的尺寸,在页面尺寸改变时同样有效.如果你在项目中遇到类似如下的需求,就需要考虑布局了: 面板填 ...
- 《第一行代码》学习笔记30-内容提供器Content Provider(3)
1."如何在自己的程序中访问其他应用程序的数据",思路->获取到该应用程序的内容URI,再借助ContentResolver进行CRUD操作. 2.要实现跨程序共享数据-&g ...
- String功能测试
package foxe; import java.io.IOException;import java.util.StringTokenizer; public class MainClass { ...
- 不同频率下的pwm配置
200k //PWM1 PWMPERDL1=0xb3; PWMPERDH1= 0x00; PWMCCNTL1=0x6B; PWMCCNTH1= ; PWMDBDY1=0x2B; //死区延时计时器 / ...
- django 学习杂记
django1.9 学习路径 http://python.usyiyi.cn/django/intro/tutorial02.html django 中url路径带参数,在view中应该如何处理 应该 ...
- Hadoop1.2.1伪分布模式安装指南
一.前置条件 1.操作系统准备 (1)Linux可以用作开发平台及产品平台. (2)win32只可用作开发平台,且需要cygwin的支持. 2.安装jdk 1.6或以上 3.安装ssh,并配置免密码登 ...