美文网首页
图片上下文的矩阵操作(平移,旋转,缩放)

图片上下文的矩阵操作(平移,旋转,缩放)

作者: 遇见灬最美的你 | 来源:发表于2016-12-01 14:25 被阅读106次

原图

平移

Paste_Image.png

旋转

Paste_Image.png

缩放

Paste_Image.png

具体代码如下

//
//  drawView.m
//  09-图片上下文的矩阵操作(了解)
//
//  Created by 李亮 on 2016/12/1.
//  Copyright © 2016年 www.thelast.com. All rights reserved.
//

#import "drawView.h"

@implementation drawView

- (void)drawRect:(CGRect)rect {
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    UIBezierPath * path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 50)];
    
    [[UIColor redColor] set];
    
    //矩阵操作
    //移动
//    CGContextTranslateCTM(ctx, 100, 100);
    //旋转
    CGContextRotateCTM(ctx, M_PI_4);
    //缩放
//    CGContextScaleCTM(ctx, 1.5, 1.5);
    
    CGContextAddPath(ctx, path.CGPath);
    
    CGContextFillPath(ctx);
}

@end

相关文章

网友评论

      本文标题:图片上下文的矩阵操作(平移,旋转,缩放)

      本文链接:https://www.haomeiwen.com/subject/ddvxmttx.html