I read several posts on this site about using drawInRect instead of CGContext drawing methods. Is he still yanking him upside down? I thought using drawInRect would print it right side up with the coordinate system coming out in the upper left corner?
-(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(); }
Notice that I am doing size.height-y-height , and if I do not, it will not go where I expect (assuming drawInRect using an overflowed coordinate system). It is displayed in the right place with the above code, but still upside down. HELP!!!!!!
UPDATE
Thanks to the answer below, this is a working method
-(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(); }
source share