iPhone How-to:图片的灰度处理
2011-04-11 16:34
183 查看
表示点击无效或者用户离线的情况下通常会使用一些灰度图片。在iPhone中如何将普通图片转换成相应的灰度图像呢?下面这段代码给出了答案。
其中,CGColorSpaceCreateDeviceGray会创建一个设备相关的灰度颜色空间的引用。
UIImage *grayImage(UIImage *source) { int width = source.size.width; int height = source.size.height; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGContextRef context = CGBitmapContextCreate (nil, width, height, 8, // bits per component 0, colorSpace, kCGImageAlphaNone); CGColorSpaceRelease(colorSpace); if (context == NULL) { return nil; } CGContextDrawImage(context, CGRectMake(0, 0, width, height), source.CGImage); UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)]; CGContextRelease(context); return grayImage; }
其中,CGColorSpaceCreateDeviceGray会创建一个设备相关的灰度颜色空间的引用。
相关文章推荐
- iPhone How-to:图片的灰度处理
- How to Create a Provisioning Profile for iPhone
- iPhone处理图片(UIImage扩展类) 自动适应frame大小方法
- iPhone开发关于icon和Default及图片处理方法[转]
- [HOW TO]如何在iPhone应用程序中发送邮件
- Atitit 图像处理 灰度图片 灰度化的原理与实现
- (zz)How to sideload apps on your iPhone using Xcode 7(无需99刀也能在真机上测试App)
- iPhone How-to:如何递归dump UIView
- [Python]图像处理日记——第一天(如何查询图片属性,数组与RGB,灰度图像如何互换)
- How to tell your iPhone application that location services are required | The Agile Warrior
- How to design a tabpanel in blackberry like iPhone style
- How To Choose The Best XML Parser for Your iPhone Project
- 简单的iphone图片处理程序
- iphone开发中对Icon等的图片的Default处理方法
- iphone开发--字体类型设置(how to set the font type)
- 图片灰度处理
- How do I lock the orientation to portrait mode in a iPhone Web Application?
- iPhone开发:如何阻止文件被iTunes和iCloud同步 How do I prevent files from being backed up to iCloud and iTunes?
- iOS学习笔记--图片灰度处理
- 四 错误处理篇 How to Fix Login Failed For User NT AUTHORITY IUSRS in SharePoint 2013 ...