您的位置:首页 > 其它

Quartz 2D 图形上下文栈 矩阵 裁剪

2015-06-30 02:24 232 查看
Quartz 2D 图形上下文栈 矩阵

//
//  DJVIew.m
//  图形上下文栈
//
//  Created by zjj on 15/6/30.
//  Copyright (c) 2015年 zjj. All rights reserved.
//

#import "DJVIew.h"

@implementation DJVIew

- (void)drawRect:(CGRect)rect
{
CGContextRef ref = UIGraphicsGetCurrentContext();
// 将ref(当前图形上下文)拷贝一份放入图形上下文栈里
CGContextSaveGState(ref);
//矩阵操作 旋转
CGContextRotateCTM(ref, M_PI_4*0.3);
// 矩阵操作 界面上所有图案缩放
CGContextScaleCTM(ref, 0.5, 0.5);
//矩阵操作 平移
CGContextTranslateCTM(ref, 100, 100);
// 设置绘图状态
[[UIColor redColor]set];
CGContextSetLineWidth(ref, 10);
CGContextSetLineCap(ref, kCGLineCapRound);

CGContextMoveToPoint(ref, 20, 35);
CGContextAddLineToPoint(ref, 88, 195);
CGContextAddEllipseInRect(ref, CGRectMake(100, 100, 100, 100));//圆
CGContextAddArc(ref,200, 200, 150, 0, M_PI*2, 0);//圆
CGContextStrokePath(ref);
//    // 设置绘图状态
//    [[UIColor blackColor]set];
//    CGContextSetLineWidth(ref, 1);
//    CGContextSetLineCap(ref, kCGLineCapButt);
// 将栈顶上下文出栈替换当前上下文
CGContextRestoreGState(ref);

CGContextAddRect(ref, CGRectMake(200, 200, 88, 88));//方
CGContextMoveToPoint(ref, 10, 50);
CGContextAddLineToPoint(ref, 266, 225);
CGContextStrokePath(ref);
}

@end


裁剪 如:任意图片裁剪为圆形头像等



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: