且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在上下文中绘制时如何翻转坐标?

更新时间:2023-01-13 12:39:57

您应该能够使用类似于以下内容的上下文转换上下文:

You should be able to transform the context using something similar to the following:

CGContextSaveGState(bitmapContext);
CGContextTranslateCTM(bitmapContext, 0.0f, originalImage.size.height);
CGContextScaleCTM(bitmapContext, 1.0f, -1.0f);

// Draw here
CGContextDrawImage(bitmapContext, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), oImageRef);

CGContextRestoreGState(bitmapContext);

翻译可能不需要图像绘制,但我需要它,文本。如果这是你在上下文中唯一要做的事情,你也可以摆脱调用来保存和恢复上下文的状态。

The translation may not be necessary for the image drawing, but I needed it when I wanted to draw inverted text. If this is the only thing you'll be doing in the context, you might also be able to get rid of the calls to save and restore the context's state.