我在这个网站上阅读了一些关于使用 drawInRect 而不是 CGContext 绘制方法的帖子。它仍然把它颠倒过来?我认为使用 drawInRect 会在坐标系位于左上角的情况下将其正面朝上打印?
-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
UIGraphicsPushContext(context);
[image drawInRect:CGRectMake(x, size.height-y-height, width, height)];
UIGraphicsPopContext();
}
请注意我正在做size.height-y-height
,如果我不这样做,它不会去我期望的地方(假设drawInRect
使用左上角坐标系)。它使用上面的代码在正确的位置呈现,但仍然是颠倒的。帮助!!!!!!
更新
感谢下面的答案,这是工作方法
-(void) drawImage:(UIImage*) image atX:(float) x andY:(float) y withWidth:(float) width andHeight:(float) height onContext:(CGContextRef) context{
UIGraphicsPushContext(context);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
[image drawInRect:CGRectMake(x, y, width, height)];
CGContextRestoreGState(context);
UIGraphicsPopContext();
}