博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
改变图片颜色(灰色显示)
阅读量:4673 次
发布时间:2019-06-09

本文共 1470 字,大约阅读时间需要 4 分钟。

UIImage+grayColor.h#import 
@interface UIImage (grayColor)+ (UIImage *)grayImage:(UIImage *)sourceImage;@endUIImage+grayColor.m#import "UIImage+grayColor.h"@implementation UIImage (grayColor)+ (UIImage *)grayImage:(UIImage *)sourceImage{ int bitmapInfo = kCGImageAlphaNone; int width = sourceImage.size.width; int height = sourceImage.size.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGContextRef context = CGBitmapContextCreate (nil, width, height, 8, // bits per component 0, colorSpace, bitmapInfo); CGColorSpaceRelease(colorSpace); if (context == NULL) { return nil; } CGContextDrawImage(context, CGRectMake(0, 0, width, height), sourceImage.CGImage); UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; CGContextRelease(context); return grayImage;}@end// 使用 UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)]; [imageView setImage:[UIImage grayImage:[UIImage imageNamed:@"dark.jpg"]]]; [self.view addSubview:imageView];

 

转载于:https://www.cnblogs.com/joesen/p/3540125.html

你可能感兴趣的文章
js代码格式化工具(格式化、压缩、加密压缩)
查看>>
HTML特殊符号
查看>>
【vijos P1914】【codevs 3904】[NOIP2014 普及组T4]子矩阵(dfs+状压dp)
查看>>
MySQL 处理海量数据时一些优化查询速度方法
查看>>
ubuntu 安装nginx 并开启目录浏览功能
查看>>
leetcode[94]Binary Tree Inorder Traversal
查看>>
nginx的addition模块在响应的前后报文添加内容与变量的运行原理
查看>>
Sql日期时间格式转换
查看>>
Winform中ComcoBox控件设置选定项
查看>>
chrome调试技巧
查看>>
concurrency runtime学习笔记之二:并行
查看>>
python基础(三)
查看>>
GraphQL实战经验和性能问题的解决方案
查看>>
MySql大数据量恢复
查看>>
java-字符串反转
查看>>
获取一个目录下的所有文件
查看>>
微软发布Sample Browser for Windows 8版:5000示例代码,"触手可及"
查看>>
Windows 10 使用问题
查看>>
linux xargs命令
查看>>
用CSS3实现图像风格
查看>>