0
对于给定的UIImage,我的目标是生成另一个UIImage,它是原始图像的对角镜像版本。我正在使用Core Graphics来实现这一点。iOS:如何使用核心图形对角镜像图像
我的尝试是,以生成仿射变换矩阵为对角镜操作如下:
| 0 1 0 |
| 1 0 0 |
| 0 0 1 |
但是得到的图像来作为旋转的图像,而不是对角镜像...
更具体地说,这里是我试过的代码:
+ (UIImage *)mirrorImageDiagonal:(UIImage *)fromImage
{
CGContextRef mainViewContentContext = MyCreateBitmapContext(fromImage.size.width, fromImage.size.height);
CGAffineTransform transform = CGAffineTransformIdentity;
transform.a = 0;
transform.b = 1;
transform.c = 1;
transform.d = 0;
transform.tx = 0;
transform.ty = 0;
CGContextConcatCTM(mainViewContentContext, transform);
// draw the image into the bitmap context
CGContextDrawImage(mainViewContentContext, CGRectMake(0, 0, fromImage.size.width, fromImage.size.height), fromImage.CGImage);
// create CGImageRef of the main view bitmap content, and then release that bitmap context
CGImageRef reflectionImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);
// convert the finished reflection image to a UIImage
UIImage *theImage = [UIImage imageWithCGImage:reflectionImage];
// image is retained by the property setting above, so we can release the original
CGImageRelease(reflectionImage);
return theImage;
}
与变换矩阵的问题?或者我如何使用Core Graphics?