我已经尝试了几天了。我正在创建一个精灵表加载器,但是我还必须能够加载面向相反方向的精灵。这涉及翻转我已经加载的图像。
我已经尝试使用 UIImageOrientation / UIImageOrientationUpMirrored 方法来执行此操作,但这绝对没有效果,只是以与以前完全相同的方向绘制框架。
从那以后,我尝试了一种稍微复杂的方法,我将在下面介绍。但是,仍然以与加载到应用程序中完全相同的方式简单地绘制图像。(未镜像)。
我已经包含了下面的方法(连同我的评论,以便您可以遵循我的思维模式),您能看到我做错了什么吗?
- (UIImage*) getFlippedFrame:(UIImage*) imageToFlip
{
//create a context to draw that shizz into
UIGraphicsBeginImageContext(imageToFlip.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//WHERE YOU LEFT OFF. you're attempting to find a way to flip the image in imagetoflip. and return it as a new UIimage. But no luck so far.
[imageToFlip drawInRect:CGRectMake(0, 0, imageToFlip.size.width, imageToFlip.size.height)];
//take the current context with the old frame drawn in and flip it.
CGContextScaleCTM(currentContext, -1.0, 1.0);
//create a UIImage made from the flipped context. However will the transformation survive the transition to UIImage? UPDATE: Apparently not.
UIImage* flippedFrame = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return flippedFrame;
}
谢谢你,盖伊。