UIView+Image
#import <UIKit/UIKit.h> @interface UIView (Image) - (UIImage *) imageByRenderingView; @end #import "UIView+Image.h" #include <QuartzCore/QuartzCore.h> @implementation UIView (Image) - (UIImage *)imageByRenderingView { UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resultingImage; // CGImageRef topOfImageCG = // CGImageCreateWithImageInRect(currImage.CGImage, // CGRectMake(0, // 0, // currImage.size.width, // currImage.size.height / 2.0)); // // UIImage *topOfImage = [UIImage imageWithCGImage:topOfImageCG]; // // CGImageRelease(topOfImageCG); } @end
将view转换成image的一个category, 注释的部分是截取一半图片的方法。