使用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();
}
    
已邀请:
    UIGraphicsBeginImageContext(imageViewSize);
CGContextRef imageContext = UIGraphicsGetCurrentContext();

// Draw the image in the upper left corner (0,0) with its actual size
CGContextDrawImage(imageContext, imageViewRect, oldImage.CGImage);

//  As it draws the image from lower right corner, 
//  following code will flip it up side down vertically.


CGContextTranslateCTM(imageContext, 0.0, 0.0);
CGContextScaleCTM(imageContext, 1.0, -1.0);

CGContextDrawImage(imageContext, imageViewRect, oldImage.CGImage);
    

要回复问题请先登录注册