Using UIImage drawInRect still makes it upside down

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(); } 
+4
source share
1 answer
  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); 
+1
source

Source: https://habr.com/ru/post/1332859/


All Articles