iOS里生成灰化(黑白)图像
2013-03-11 13:20
323 查看
代码的目的是根据一个UIImage生成对应的灰化(黑白)UIImage.
以下代码源自stackoverflow里的一个回复,可惜原文链接已经找不到了。
以下代码源自stackoverflow里的一个回复,可惜原文链接已经找不到了。
- (UIImage*) convertImageToGreyScale:(UIImage*) image { // Create image rectangle with current image width/height CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); // Grayscale color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); // Create bitmap content with current image size and grayscale colorspace CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone); // Draw image into current context, with specified rectangle // using previously defined context (with grayscale colorspace) CGContextDrawImage(context, imageRect, [image CGImage]); // Create bitmap image info from pixel data in current context CGImageRef imageRef = CGBitmapContextCreateImage(context); // Create a new UIImage object UIImage *newImage = [UIImage imageWithCGImage:imageRef]; // Release colorspace, context and bitmap information CGColorSpaceRelease(colorSpace); CGContextRelease(context); CFRelease(imageRef); // Return the new grayscale image return newImage; }
相关文章推荐
- iOS 开发 二维码生成大全(黑白/彩色二维码和带图片的二维码)详解
- Delphi XE10写的转换图像文件大小,用于生成安卓和IOS的小图标和启动画面
- C#图像处理类(使用此类可实现生成锐化效果、黑白效果和灰度效果)
- iOS 图像之生成多彩颜色
- iOS图像处理(4)坐标变化
- ios生成pem推送证书
- 图像生成与图像模型——摄像机
- C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
- iOS-生成Bundle包-引入bundle-使用bundle
- iOS根据接口生成二维码
- iOS生成本地验证码
- OpenSSL使用1(用OpenSSL生成自签名证书在IIS上搭建Https站点)(用于iOS的https访问)
- 【iOS开发】生成Appicon图标、为iOS应用添加图标
- IOS下,利用捏合手势实现图像缩放和显示
- iOS中图形图像处理第一部分:位图图像原图修改
- iOS中的生成随机数方法
- iOS开发笔记--iOS 事件处理机制与图像渲染过程
- C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
- iOS Core Animation Advanced Techniques(七):高效绘图、图像IO以及图层性能
- ios开发静态库生成