圖片上下文的矩陣操作(平移,旋轉,縮放)

原圖

平移

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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容