CTM(绘图)
来源:互联网 发布:windows资源管理器黑屏 编辑:程序博客网 时间:2024/05/16 17:17
#import "DrawView.h"
#define edg 10
@implementation DrawView
- (void)drawRect:(CGRect)rect
{
// self.backgroundColor = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"circle+.png"];
[image drawInRect:CGRectMake(0, 0, 50, 50)];
CGContextSaveGState(context);//保存图形上下文
CGContextTranslateCTM(context, 50, 50);//平行当前上下文的变换矩阵
[image drawInRect:CGRectMake(100, 100, 50, 50)];//此图形为平移后的位置+设置的位置
CGContextRestoreGState(context);//恢复图形上下文
CGContextAddRect(context, CGRectMake(100, 100, 50, 50));
CGContextDrawPath(context, kCGPathFillStroke);
CGContextSaveGState(context);
CGContextRotateCTM(context, -M_PI_4);//旋转当前上下文的变换矩阵
[image drawInRect:CGRectMake(200, 200, 50, 50)];
CGContextRestoreGState(context);
CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(5, 5), 2);
//创建透明图层,在Begin和End之间的图形会看作一个整体
CGContextBeginTransparencyLayer(context, NULL);
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
CGContextFillRect(context, CGRectMake(0, 100, 50, 50));
CGContextSetRGBFillColor(context, 0, 1, 0, 1);
CGContextFillRect(context, CGRectMake(0, 275, 50, 50));
CGContextSetRGBFillColor(context, 0, 0, 1, 1);
CGContextFillEllipseInRect(context, CGRectMake(0, 300, 50, 50));
CGContextEndTransparencyLayer(context);
//截图
CGContextRestoreGState(context);
UIImage *image1 = [UIImage imageNamed:@"18.jpg"];
[image1 drawInRect:CGRectMake(100, 250, image1.size.width, image1.size.height)];
CGRect rect1 = CGRectMake(edg, 0, image1.size.width-2*edg, image1.size.height-4*edg);
CGImageRef dest = CGImageCreateWithImageInRect(image1.CGImage, rect1);//从原始图像截取一个矩形区域
UIImage *image2 = [UIImage imageWithCGImage:dest];//转化为UIimage对象
[image2 drawInRect:CGRectMake(200, 0, image2.size.width, image2.size.height)];
}
@end
#define edg 10
@implementation DrawView
- (void)drawRect:(CGRect)rect
{
// self.backgroundColor = [UIColor redColor];
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"circle+.png"];
[image drawInRect:CGRectMake(0, 0, 50, 50)];
CGContextSaveGState(context);//保存图形上下文
CGContextTranslateCTM(context, 50, 50);//平行当前上下文的变换矩阵
[image drawInRect:CGRectMake(100, 100, 50, 50)];//此图形为平移后的位置+设置的位置
CGContextRestoreGState(context);//恢复图形上下文
CGContextAddRect(context, CGRectMake(100, 100, 50, 50));
CGContextDrawPath(context, kCGPathFillStroke);
CGContextSaveGState(context);
CGContextRotateCTM(context, -M_PI_4);//旋转当前上下文的变换矩阵
[image drawInRect:CGRectMake(200, 200, 50, 50)];
CGContextRestoreGState(context);
CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(5, 5), 2);
//创建透明图层,在Begin和End之间的图形会看作一个整体
CGContextBeginTransparencyLayer(context, NULL);
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
CGContextFillRect(context, CGRectMake(0, 100, 50, 50));
CGContextSetRGBFillColor(context, 0, 1, 0, 1);
CGContextFillRect(context, CGRectMake(0, 275, 50, 50));
CGContextSetRGBFillColor(context, 0, 0, 1, 1);
CGContextFillEllipseInRect(context, CGRectMake(0, 300, 50, 50));
CGContextEndTransparencyLayer(context);
//截图
CGContextRestoreGState(context);
UIImage *image1 = [UIImage imageNamed:@"18.jpg"];
[image1 drawInRect:CGRectMake(100, 250, image1.size.width, image1.size.height)];
CGRect rect1 = CGRectMake(edg, 0, image1.size.width-2*edg, image1.size.height-4*edg);
CGImageRef dest = CGImageCreateWithImageInRect(image1.CGImage, rect1);//从原始图像截取一个矩形区域
UIImage *image2 = [UIImage imageWithCGImage:dest];//转化为UIimage对象
[image2 drawInRect:CGRectMake(200, 0, image2.size.width, image2.size.height)];
}
@end
0 0
- CTM(绘图)
- iOS绘图详解-多种绘图方式、裁剪、滤镜、移动、CTM
- iOS 2D绘图详解(Quartz 2D)之Transform(CTM,Translate,Rotate,Scale)
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM 转换矩阵
- transforms CTM,变换矩阵
- Transforms CTM, 转换矩阵
- CTM R9 notes: Key Functionality
- Quartz Transforms CTM, 转换矩阵
- Quartz 2D与CTM
- Transform(CTM,Translate,Rotate,Scale)
- 第十一周项目2-求最大公约数
- repo和git使用技巧
- hadoop入门-在windows上安装,测试hadoop
- 断言assert()函数的使用
- Xcode和github入门详细教程!
- CTM(绘图)
- Android突破一之Bitmap、BitmapFactory、BitmapDrawable类
- Hbase 查询为什么快
- rk3128 camera sensor的注册
- spring学习之@ModelAttribute运用详解
- Convolutional Networks for Images,Speech,and Time-series
- Google图片搜索的原理
- UVA 11354 Bond (LCA + MST) (堆优化的Prim)
- 在Linux下安装kaldi工具箱