BitMap类型的图形上下文
来源:互联网 发布:中文翻译蒙语软件下载 编辑:程序博客网 时间:2024/06/03 22:57
1. 系统提供的上下文
Quartz2D提供了以下几种类型的GraphicsContext:
>Bitmap GraphicsContext(图片类型的上下文)
>> PDF Graphics Context
>> Window Graphics Context
>> Layer Graphics Context(UI控件)
>> Printer Graphics Context
关于图片类型的上下文:
1> 图片类型的上下文需要手动创建,大小也需要手动来传。
2> 图片类型的上下文需要开启和关闭;
3> 使用图片类型上下文的一个好处是可以获取一个image对象,并且保存到沙盒或者相册中;
4> 图片类型的上下文可以在任何地方使用。
2. 图形上下文的开启与关闭
a.图片上下文的两种开启方法:
void UIGraphicsBeginImageContext(CGSize size);
void UIGraphicsBeginImageContextWithOptions(CGSizesize, BOOL opaque, CGFloat scale)【一般只用这个方法】
b.图片上下文的关闭方法:
void UIGraphicsEndImageContext(void);
c.参数解析:
CGSizesize 是开启一个Bitmap 类型的图形上下文的大小
BOOLopaque Bitmap 类型的图形上下文是否透明(NO表示透明)
CGFloatscale 缩放因子(一般设置为0)
如果CGFloat scale = 0 表示默认为设备的缩放因子,iPhone6时为2,iPhone6plus时为3;
d.两种开启方法的区别:
UIGraphicsBeginImageContext(CGSizeMake(200,200));
该方法输出的图片的像素是200*200;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(200,200), NO, 3);
该方法输出的图片的像素是(200*3)*(200*3),即600*600
两个开启方法的等价方式:
UIGraphicsBeginImageContext(CGSizeMake(200,200)) <=>
UIGraphicsBeginImageContextWithOptions(CGSizeMake(200,200), NO, 1);
3. Bitmap类型上下文的一个Demo
// 开启图片上下文
UIGraphicsBeginImageContextWithOptions(CGSizeMake(200,200), NO, 0);
// 获取当前的上下文
CGContextRefctx = UIGraphicsGetCurrentContext();
// 绘制圆
CGContextAddArc(ctx,100, 100, 80, 0, 2 * M_PI, 1);
// 渲染
CGContextStrokePath(ctx);
// 从图片类型的上下文当中 取出 image对象
UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
// 关闭图片上下文
UIGraphicsEndImageContext();
// 获取doc的目录
NSString* docPath =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)[0];
// 文件的路径
NSString* filePath =
[docPathstringByAppendingPathComponent:@"xx.png"];
// 把image对象转化成data的对象
NSData*data = UIImagePNGRepresentation(image);
// 通过data对象 调用write to file 的方法写入到沙盒当中
[datawriteToFile:filePath atomically:YES];
- BitMap类型的图形上下文
- ios UIKit的图形上下文
- Bitmap上下文
- 图形上下文
- 图形设备/图形上下文
- iOS画图中 图形上下文的管理
- ios-图片类型的上下文
- bitmap上下文--裁剪图片
- 画布上的图形保存未bitmap
- 图形上下文栈
- 32.图形上下文
- 37.图形上下文栈
- Quarzt2D--图形上下文栈
- Quartz2D-图形上下文栈
- ios图形上下文CGContext
- Quartz2D:图形上下文栈
- iOS - 图形上下文使用
- 深入理解图形上下文
- 黑盒测试
- 各大it企业编程笔试题,答案自己做的,大家批评指正(更新中)
- Android高效加载大图、多图解决方案,有效避免程序OOM
- GitHub详细教程
- 百度编辑器UEditor 简单使用
- BitMap类型的图形上下文
- Selecting MV Strategy for Temporal ERC
- hihoCoder 1234 Fractal——ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
- 实现一个数组中奇数和偶数分开,奇数在前部分,偶数在后部分 时间复杂度为O(n),空间复杂度为O(1)
- 更加丰富的一年——我的14-15
- 校招笔试/面试记录
- java计算器小程序
- 计算器
- SQL server 2008数据库的备份与还原