Quartz 实现画图片、写文字、画线、椭圆、矩形、棱形等。三

/*绘制图片
     NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
     UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];
     //[myImageObj drawAtPoint:CGPointMake(0, 0)];
     [myImageObj drawInRect:CGRectMake(0, 0, 320, 480)];
 
     NSString *s = @"我的小狗";
 
     [s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]];
*/
     
   /*
     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
     UIImage *img = [UIImage imageWithContentsOfFile:path];
     CGImageRef image = img.CGImage;
     CGContextSaveGState(context);
     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
     CGContextDrawImage(context, touchRect, image);
     CGContextRestoreGState(context);
    */
   
     
     /*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
     UIImage *img = [UIImage imageWithContentsOfFile:path];
     CGImageRef image = img.CGImage;
     CGContextSaveGState(context);
 
     CGContextRotateCTM(context, M_PI);
     CGContextTranslateCTM(context, -img.size.width, -img.size.height);
 
     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
     CGContextDrawImage(context, touchRect, image);
     CGContextRestoreGState(context);*/
 
/*
     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
     UIImage *img = [UIImage imageWithContentsOfFile:path];
     CGImageRef image = img.CGImage;
     
     CGContextSaveGState(context);
 
     CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI);
     myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height);
     CGContextConcatCTM(context, myAffine);
 
     CGContextRotateCTM(context, M_PI);
     CGContextTranslateCTM(context, -img.size.width, -img.size.height);
 
     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
     CGContextDrawImage(context, touchRect, image);
     CGContextRestoreGState(context);
*/

猜你喜欢

转载自blog.csdn.net/huangmindong/article/details/24709541