簡體   English   中英

旋轉石英圖像? 圖像顛倒了! (蘋果手機)

[英]Rotate image in Quartz? Image is upside down! (iPhone)

  • 我不想改變整個上下文。

我正在用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:

我將如何旋轉/變形?

為什么不使用

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

這將為您處理坐標變換。


如果必須使用CGContextDrawImage ,則轉換整個上下文是唯一的方法。 您可以使用以下方法恢復到原始狀態:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM