CGContextSetTextMatrix是否适用于屏幕外位图? [英] Does CGContextSetTextMatrix work for offscreen bitmaps?
本文介绍了CGContextSetTextMatrix是否适用于屏幕外位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 CGBitmapContextCreate()
中的上下文在屏幕外创建图像。
I'm creating an image offscreen using a context from CGBitmapContextCreate()
.
在绘制文本时,我尝试使用:
While drawing text, I tried to use the:
CGContextSetTextMatrix(contextRef, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
但我的文字仍然颠倒了。如果我使用标准转换,那是正确的:
but my text was still upside down. If I used the standard transforms it was correct:
CGContextTranslateCTM(contextRef, 0.0, contextRect.size.height);
CGContextScaleCTM(contextRef, 1.0, -1.0);
我的问题是 CGContextSetTextMatrix
是否适用屏幕外的位图?可能是我做错了。
My question is should the CGContextSetTextMatrix
work for an offscreen bitmap? Maybe I was doing something wrong.
推荐答案
我遇到了同样的问题,并使用以下方法解决了:
I ran into same problem, and solved by using:
CGContextTranslateCTM(context, 0.0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
......
CGGlyph glyphs[text.length];
CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)(fontName), fontSize, NULL);
CTFontGetGlyphsForCharacters(fontRef, (const unichar*)[text cStringUsingEncoding:NSUnicodeStringEncoding], glyphs, text.length);
CGContextShowGlyphsAtPoint(context, destX, destY, (const CGGlyph *)glyphs, ce.text.length);
仅供参考。
这篇关于CGContextSetTextMatrix是否适用于屏幕外位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文