Sunday, June 19, 2011

Vertical flip in CGontextRef.

Vertical Flip- which means top to down.

If you try to draw an image on CGContextRef , it will appear upside down, you will have to apply transformation on it set it right.Make sure you add QuartzCore.
 #import


1. Drawing an image on CGContextRef without transformation

CGContextRef context=UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, 768, 1024), [UIImage imageNamed:@"1.jpg"].CGImage);













2. Drawing an image on CGContextRef with transformation of vertical flip

CGContextRef context=UIGraphicsGetCurrentContext();
CGAffineTransform flipTransform = CGAffineTransformMake( 1, 0, 0, -1, 0, self.frame.size.height);
CGContextConcatCTM(context, flipTransform);
CGContextDrawImage(context, CGRectMake(0, 0, 768, 1024), [UIImage imageNamed:@"1.jpg"].CGImage);









For horizontal flip, you can read this article : LINK

No comments:

Post a Comment