【发布时间】:2010-07-23 15:45:27
【问题描述】:
大家好;
我正在尝试手动(不使用子图层)在 CATiledLayer 中绘制图像,但它的行为与定义的解决方案不同。我知道,当您调用“CGContextDrawImage”时,您必须缩放和平移以翻转它,但我无法终生使用它。
我有一个方法叫
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image
在
中被多次调用 - (void)drawInContext:(CGContextRef)context
渲染所有进入 CATileLayer 的图像。
以下不渲染图像:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
CGContextRestoreGState(context);
以下生成图像但渲染不正确:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextDrawImage(context, rect, image.CGImage);
明智地这样做:
- (void)drawInContext:(CGContextRef)context Image:(UIImage *)image {
CGRect rect = CGRectMake(x, y, image.size.width, image.size.height);
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, image.CGImage);
我也试过了:
UIGraphicsBeginImageContext
UIGraphicsEndImageContext
和
UIGraphicsPushContext
UIGraphicsPopContext
所有都不起作用。我在这里遗漏了一些基本的东西,我怀疑我保存上下文的方法不起作用。
【问题讨论】:
标签: iphone quartz-graphics ios4