使用CGContext时的图像绘制问题。图像水平镜像

时间:2010-11-18 22:47:07

标签: iphone drawing uiimage cgcontext

当我使用下面的代码在UIView上绘制UIImage* image时,图像会水平镜像。就像我绘制4一样,它就是这样绘制的alt text ..

CGRect rect = CGRectMake(x, y, imageWidth, imageHeight);
CGContextDrawImage((CGContextRef) g, rect, ((UIImage*)image).CGImage);

那是问题???我做错了???或者如果有人知道如何解决它,请让我也知道。我非常感谢提前。

感谢loooooooooot。

2 个答案:

答案 0 :(得分:5)

请参阅:CGContextDrawImage draws image upside down when passed UIImage.CGImage

使用[image drawInRect:rect]代替CGContextDrawImage

答案 1 :(得分:2)

你可以使用

以正确的方式转动图片
CGAffineTransform transform =CGAffineTransformMakeTranslation(0.0, height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(context, transform);

//draw image in the context
CGContextDrawImage(context, rect, ((UIImage*)image).CGImage);

使用[image drawInRect:rect]使用默认上下文即屏幕,您无法将其设置为当前上下文,例如如果你想把它作为按钮的ima

的一部分