【问题标题】:Rotate image in Quartz? Image is upside down! (iPhone)在 Quartz 中旋转图像?图像是颠倒的! (苹果手机)
【发布时间】:2010-04-05 14:09:57
【问题描述】:
  • 我不想转换整个上下文。

我正在用 Quartz 制作一个游戏,我正在用线条、矩形和椭圆来绘制我的玩家。

然后我在屏幕左上角的 0,0 处渲染了 diamong.png。

问题是……

它会颠倒渲染!

如何将它旋转 180 度?

这是我的一些代码:

CGImageRef diamondImage = CGImageRetain([UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Diamond.png" ofType:nil]].CGImage);
CGContextDrawImage(context, CGRectMake(0, 0, 32, 24), diamondImage);

如果有任何帮助,我正在使用横​​向模式,主页按钮在右侧。它在我的 .plist 和 ViewController 中都定义了

-shouldAutorotateToInterfaceOrientation:interfaceOrientation:

我将如何旋转/变换它?

【问题讨论】:

    标签: iphone objective-c image rotation quartz-graphics


    【解决方案1】:

    为什么不使用

    [[UIImage imageWithContentsOfFile:…] drawInRect:CGRectMake(0, 0, 32, 24)];
    

    ?这会为您处理坐标变换。


    如果必须使用CGContextDrawImage,则转换整个上下文是唯一的方法。您可以使用以下命令恢复到原始状态:

    CGContextSaveGState(context);
    // transform ...
    // draw ...
    CGContextRestoreGState(context);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-26
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2013-11-21
      • 1970-01-01
      相关资源
      最近更新 更多