Skip to content

Instantly share code, notes, and snippets.

@Kursulla
Last active December 17, 2015 18:49
Show Gist options
  • Save Kursulla/5656038 to your computer and use it in GitHub Desktop.
Save Kursulla/5656038 to your computer and use it in GitHub Desktop.
Split one image into two images and place them into separated containers [Objective-C, objc, xcode, ios]
UIImage *image = [UIImage imageNamed:@"some_image.png"];
CGImageRef tmpImgRef = image.CGImage;
//Taking left part of image from 0 to half of width
CGImageRef leftImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(0, 0, image.size.width/2.0, image.size.height ));
UIImage *leftUIImage = [UIImage imageWithCGImage:leftImgRef];
CGImageRelease(leftImgRef);
//Taking right of image from half of width to full width
CGImageRef rightImgRef = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(image.size.width / 2.0, 0, image.size.width/2.0, image.size.height));
UIImage *rightUIImage = [UIImage imageWithCGImage:rightImgRef];
CGImageRelease(rightImgRef);
//Placing images into separated containers (UIImageView) in order to manipulate with them
[_leftImage setImage:leftUIImage];
[_rightImage setImage:rightUIImage];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment