0

I'm learning about basic manipulation of UIImages using Objective-C on iOS. Say I have a square 128x128 image. How can I crop the bottom half of the image and store just the top half in a 128x64 image?

SundayMonday
  • 19,147
  • 29
  • 100
  • 154

1 Answers1

4

What you do is get a smaller CGImageRef from the UIImage's CGImage:

CGImageCreateWithImageInRect([image CGImage], someRect);

With that image you can then create a new image:

UIImage *nImage = [UIImage alloc] initWithCGImage:nImageRef];

Oops almost forgot, after you do the above:

CGImageRelease(nImageRef);
David H
  • 40,852
  • 12
  • 92
  • 138