UIImage vertikal spiegeln


Aus Macwrench

Wechseln zu: Navigation, Suche
+ (UIImage *)flipImage:(UIImage*)image vertically:(BOOL)vertically
{
	UIGraphicsBeginImageContext(image.size);
	CGContextRef context = UIGraphicsGetCurrentContext();
	CGAffineTransform flip;
	if(vertically)
	{
		flip = CGAffineTransformMake(1, 0, 0, -1, 0, image.size.height);
	}
	else
	{
		flip = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, image.size.width, 0.0);
	}
	CGContextConcatCTM(context, flip);
	CGContextDrawImage(context, CGRectMake(0.0, 0.0, image.size.width, image.size.height), [image CGImage]);
	UIImage *flippedImage = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	return flippedImage;
}
Ansichten