UIImage,CGImage和CGImageRef 区别
2016-03-31 09:55
489 查看
CGImage和CGImageRef这两个应当是用来重绘图形的类,它们在应用时是按照图像的像素矩阵来绘制图片的,它们可以用来处理bitmap。
CGImageRef与UIImage的互转
CGImageRef转换成UIImage
CGImageRef iOffscreen = CGBitmapContextCreateImage(context);
UIImage* image = [UIImage imageWithCGImage: iOffscreen];
2.UIImage转换成CGImageRef
UIImage *loadImage=[UIImage imageNamed:@”comicsplash.png”];
CGImageRef cgimage=loadImage.CGImage;
UIView转UIImage(截屏,UIGraphicsBeginImageContextWithOptions函数的使用)
// 需要转成image的view:captureAndSaveView
UIGraphicsBeginImageContextWithOptions(captureAndSaveView.frame.size, NO, 1.0); //NO,YES 控制是否透明
[captureAndSaveView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 生成后的image
哪位大侠解释下UIColor与CGColor,这俩有啥区别
CGColor就是UIColor的一个属性
有些设定颜色 要求的类型就是CGColor的所以用CGColor
如CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor);
另外下面一个CGColor的用法希望能帮到你
const CGFloat *components = CGColorGetComponents(color.CGColor);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
CGImageRef与UIImage的互转
CGImageRef转换成UIImage
CGImageRef iOffscreen = CGBitmapContextCreateImage(context);
UIImage* image = [UIImage imageWithCGImage: iOffscreen];
2.UIImage转换成CGImageRef
UIImage *loadImage=[UIImage imageNamed:@”comicsplash.png”];
CGImageRef cgimage=loadImage.CGImage;
UIView转UIImage(截屏,UIGraphicsBeginImageContextWithOptions函数的使用)
// 需要转成image的view:captureAndSaveView
UIGraphicsBeginImageContextWithOptions(captureAndSaveView.frame.size, NO, 1.0); //NO,YES 控制是否透明
[captureAndSaveView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 生成后的image
哪位大侠解释下UIColor与CGColor,这俩有啥区别
CGColor就是UIColor的一个属性
有些设定颜色 要求的类型就是CGColor的所以用CGColor
如CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor);
另外下面一个CGColor的用法希望能帮到你
const CGFloat *components = CGColorGetComponents(color.CGColor);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
相关文章推荐
- continue 与break 的区别
- IOS学习笔记45--UITableView性能优化
- NSTimer 回调事件被UI交互阻塞的解决方法
- UISplitViewController
- 使用SoapUI 测试Web Service
- UIView的一个弹出动画
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
- 编译错误 --- does not name a type和field `XX' has incomplete type
- ios9中 UIStackView的使用
- CodeForces 632D Longest Subsequence(数论)
- UIAlertView利用runtime传值
- [转] How to change font settings for all UI elements (toolbar and context menus, property editors, etc.)
- 设置UINavigationBar的UI
- IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)
- 3分钟看完Build2016 Day 1 Keynote
- 微软Build 2016开发者大会--兑换承诺
- invalid request block size: 21573 (max 4096)...skip错误原因
- QT22 database values in QLineEdit or textbox if select QListView
- QT20 database values in QLineEdit or textbox if select combobox
- QT19 How to link QComboBox with sqlite Database values