Quartz2D——旋转、平移、缩放、剪切圆形图片
来源:互联网 发布:单片机工程师 名称 编辑:程序博客网 时间:2024/05/17 03:34
注:旋转、平移、缩放,必须放在画图之前
平移:
<span style="font-size:18px;">// 获取上下文 CGContextRef context = UIGraphicsGetCurrentContext(); // 画一个三角形 // 定义三个点 CGPoint point[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, point, 3); // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context); #warning 旋转、平移、缩放,都要放在画图之前 // 平移 CGContextTranslateCTM(context, 100, 0); // 画第二个三角形 // 定义三个点 CGPoint points[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, points, 3); [[UIColor whiteColor] set]; // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context);</span>
效果:
旋转:围绕左上角(0,0)旋转
// 获取上下文 CGContextRef context = UIGraphicsGetCurrentContext(); // 画一个三角形 // 定义三个点 CGPoint point[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, point, 3); // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context);
// 旋转 // 负数:逆时针 // 围绕左上角(0,0)旋转 CGContextRotateCTM(context, - M_PI * 0.125); // 画第二个三角形 // 定义三个点 CGPoint points[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, points, 3); [[UIColor whiteColor] set]; // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context);效果:
缩放:
// 获取上下文 CGContextRef context = UIGraphicsGetCurrentContext(); // 画一个三角形 // 定义三个点 CGPoint point[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, point, 3); // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context); // 缩放 CGContextScaleCTM(context, 3, 4); // 画第二个三角形 // 定义三个点 CGPoint points[3] = {{50, 50}, {100, 80}, {10, 80}}; CGContextAddLines(context, points, 3); [[UIColor whiteColor] set]; // 合并路径 CGContextClosePath(context); // 渲染 CGContextStrokePath(context);效果:
裁剪圆形图片:
// 获取图形上下文 CGContextRef context = UIGraphicsGetCurrentContext(); // 设置图片的rect CGRect imageRect = CGRectMake(0, 0, rect.size.width, rect.size.height); // 在rect中画一个内切圆 CGContextAddEllipseInRect(context, imageRect); // 剪掉圆外面的部分 CGContextClip(context); // 只把图片显示在UIView上 UIImage *image = [UIImage imageNamed:@"papa"]; [image drawInRect:imageRect]; // 添加一个圆形的边框 // 设置边框颜色 [[UIColor blueColor] set]; // 设置线宽 CGContextSetLineWidth(context, 5); // 画圆 CGContextAddEllipseInRect(context, imageRect); // 渲染 CGContextStrokePath(context);
效果:
0 0
- Quartz2D——旋转、平移、缩放、剪切圆形图片
- Quartz2D-平移,旋转,缩放
- Quartz2D-圆形图片剪切
- Quartz2D-3(旋转、平移、缩放)
- Quartz2D (5)旋转,缩放,平移
- Quartz2D——图片水印,图片剪切
- Android 图片旋转 缩放 平移
- 矩阵运算——平移,旋转,缩放
- 矩阵运算——平移,旋转,缩放
- 矩阵运算——平移,旋转,缩放
- 矩阵运算——平移,旋转,缩放
- Android 图片的平移、缩放、旋转demo
- wpf 图片平移、旋转和缩放
- iOS开发UI篇—Quartz2D使用(图片剪切)
- iOS开发UI篇—Quartz2D使用(图片剪切)
- iOS开发UI篇—Quartz2D使用(图片剪切)
- iOS 图片编辑——缩放剪切
- quartz2D 图片剪切
- 超实用的JavaScript代码段 Item3 --图片轮播效果
- IOS学习基础-基础英语单词<01>
- IOS开发笔记32-UITableView(3)
- 记录几个 CALayer 的重要属性 (二)
- 软件测试会大概问的一些问题整理
- Quartz2D——旋转、平移、缩放、剪切圆形图片
- UIImage的分类
- Ligerui表格基本操作(一)
- 在servlet中实现页面跳转
- Android Asynchronous Http Client
- c++中各个数据类型的大小
- 快速创建一个UIBarButtonItem
- android窗口管理
- bzoj1606【Usaco2008 Dec】Hay For Sale 购买干草