UIImage获取灰度图像
2016-05-05 16:19
525 查看
#import <UIKit/UIKit.h>
@interface UIImage(grayImage)
-(UIImage*)getGrayImage;
@end
#import "UIImage+grayImage.h"
@implementation UIImage(grayImage)
-(UIImage*)getGrayImage{
int width =
self.size.width;
int height =
self.size.height;
CGColorSpaceRef colorSpace =
CGColorSpaceCreateDeviceGray();
CGContextRef context =
CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);
if (context ==
NULL) {
return
nil;
}
CGContextDrawImage(context,CGRectMake(0,
0, width, height), self.CGImage);
UIImage *grayImage = [UIImage
imageWithCGImage:CGBitmapContextCreateImage(context)];
CGContextRelease(context);
return grayImage;
}
@end
@interface UIImage(grayImage)
-(UIImage*)getGrayImage;
@end
#import "UIImage+grayImage.h"
@implementation UIImage(grayImage)
-(UIImage*)getGrayImage{
int width =
self.size.width;
int height =
self.size.height;
CGColorSpaceRef colorSpace =
CGColorSpaceCreateDeviceGray();
CGContextRef context =
CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);
if (context ==
NULL) {
return
nil;
}
CGContextDrawImage(context,CGRectMake(0,
0, width, height), self.CGImage);
UIImage *grayImage = [UIImage
imageWithCGImage:CGBitmapContextCreateImage(context)];
CGContextRelease(context);
return grayImage;
}
@end
相关文章推荐
- 怎样使用UGUI
- IO学习(十一)利用字节数组流实现文件拷贝,QuesRemain
- UILabe详解 for ios
- NUI控件扩展
- Android Studio里面的Build.gradle的详细配置说明
- The currently displayed page contains invalid values
- ionic build ios 没有任何输出和响应
- easyui-DataGrid基本用法
- 因为锁等待导致的慢查询不会改变状态变量slow_queries值
- UITableViewStyleGrouped的间距问题
- 层和UIView的区别是什么?
- Electron实战:创建ELectron开发的window应用安装包
- C#中跨线程操作控件 --- InvokeRequired 属性 与Invoke方法
- .NoHostAvailableException: All host(s) tried for query failed (no host was tried)
- EasyUI学习总结(六)——EasyUI布局
- EasyUI学习总结(五)——EasyUI组件使用
- EasyUI学习总结(四)——parser源码分析
- EasyUI学习总结(三)——easyloader源码分析
- EasyUI学习总结(二)——easyloader分析与使用
- ios UITableview 刷新某一个cell 或 section