使用UIImage drawInRect仍然将它颠倒过来
我在本网站上看过一些关于使用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
使用了一个topleft坐标系)。它使用上面的代码呈现在正确的位置,但仍然是颠倒的。救命!!!!!!
UPDATE
由于下面的答案,这是工作方法
-(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();
}
没有找到相关结果
已邀请:
1 个回复
裸雷胜檀哭