How to merge one or more images
- (UIImage *)combineImage:(UIImage *)imageA imageB:(UIImage *)imageB
{
UIGraphicsBeginImageContext(imageA.size);
[imageA drawInRect:CGRectMake(0, 0, imageA.size.width, imageA.size.height)];
[imageB drawInRect:CGRectMake(0, 0, imageB.size.width, imageB.size.height)];
UIImage *combinatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return combinatedImage;
}
How to resize
#define kAppIconWidth 84
#define kAppIconHeight 66
// in UIImage *image your own instance
if (image.size.width > kAppIconWidth || image.size.height > kAppIconHeight) {
CGSize itemSize = CGSizeMake(kAppIconWidth, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
How to crop an image area
- (UIImage *)cropImage:(UIImage *)image cropRect:(CGRect)rect
{
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
return newImage;
}
Related