上述答复中,没有一个回答问题部分,而问题部分反映的是一半的图像,并不影响整个形象。 解决办法的混合导致以下样本功能:你可用作UIImage+等类。 镜子:
(UIImage *) horizontalMirror {
UIImageOrientation flippedOrientation = UIImageOrientationUpMirrored;
switch (self.imageOrientation) {
case UIImageOrientationUp: break;
case UIImageOrientationDown: flippedOrientation = UIImageOrientationDownMirrored; break;
}
UIImage * flippedImage = [UIImage imageWithCGImage:self.CGImage scale:1.0 orientation:flippedOrientation];
CGImageRef inImage = self.CGImage;
CGContextRef ctx = CGBitmapContextCreate(NULL,
CGImageGetWidth(inImage),
CGImageGetHeight(inImage),
CGImageGetBitsPerComponent(inImage),
CGImageGetBytesPerRow(inImage),
CGImageGetColorSpace(inImage),
CGImageGetBitmapInfo(inImage)
);
CGRect cropRect = CGRectMake(flippedImage.size.width/2, 0, flippedImage.size.width/2, flippedImage.size.height);
CGImageRef TheOtherHalf = CGImageCreateWithImageInRect(flippedImage.CGImage, cropRect);
CGContextDrawImage(ctx, CGRectMake(0, 0, CGImageGetWidth(inImage), CGImageGetHeight(inImage)), inImage);
CGAffineTransform transform = CGAffineTransformMakeTranslation(flippedImage.size.width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
CGContextConcatCTM(ctx, transform);
CGContextDrawImage(ctx, cropRect, TheOtherHalf);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return finalImage;
}