Turn image upside down (Quartz 2D)

Discussion in 'iOS Programming' started by xArtx, Jul 15, 2012.

  1. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi Guys,
    I'm using this code to draw an image:

    Code:
        UIImage *myImage = [UIImage imageNamed:@"Sun.png"]; // sun in sky
        CGPoint imagePoint = CGPointMake(30, 266);
        [myImage drawAtPoint:imagePoint];
    
    How can I turn it upside down without providing a different source image?
    I would also like to flip it vertically.
    Thanks, Art.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Hi, I was scanning the Apple docs hoping to find a useful specific part to read, but instead I found this:

    Code:
    CGContextScaleCTM(graphicsContext, 1.0, -1.0);
    That should horizontally flip your image... I think it'll also move it downwards, so you'll need to translate it upwards by one picture height.

    Here's the apple doc I found that code excerpt in:
    http://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/graphicsdrawingoverview/graphicsdrawingoverview.html
     
  3. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    Found this which works:
    Code:
    UIImage* flippedImage = [UIImage imageWithCGImage:myImage.CGImage  scale:1.0 orientation: UIImageOrientationDown];
    
    Flips horizontal & vertical :)
    Goes after the first line posted above.
     

Share This Page