我已经尝试了几天。我正在创建一个精灵表单加载器,但我也必须能够加载面向相反方向的精灵。这需要翻转已经加载的图像。
我已经尝试使用UIImageOrientation/UIImageOrientationUpMirrored方法来实现这一点,但是这完全没有效果,只是以与之前完全相同的方向绘制帧。
我随后尝试了一种稍微复杂一些的方法,我将在下面包含。但是,它仍然只是以与应用程序加载的方式完全相同的方式绘制图像(未镜像)。
我在下面包含了该方法(以及我的注释,以便您可以跟随我的思维模式),您能看出我做错了什么吗?
谢谢,Guy。
我已经尝试使用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;
}
谢谢,Guy。