我一直使用此方法将UIView
转换为UIImage
。即视图的屏幕快照-
@interface UIView(Extended)
- (UIImage *) imageByRenderingView;
@end
@implementation UIView(Extended)
- (UIImage *)imageByRenderingView
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}
@end
为了使用它,我这样做-
UIImage *currImage = [self.view imageByRenderingView];
这给出了整个UIView
的图像表示。现在我想要2张图片,一张是UIView
的上半部分,另一张是下半部分。我该怎么做?
发布于 2011-08-24 23:03:36
您可以使用以下代码将UIImage
一分为二:
CGImageRef topOfImageCG =
CGImageCreateWithImageInRect(currImage.CGImage,
CGRectMake(0,
0,
currImage.size.width,
currImage.size.height / 2.0));
UIImage *topOfImage = [UIImage imageWithCGImage:topOfImageCG];
CGImageRelease(topOfImageCG);
https://stackoverflow.com/questions/7177637
复制相似问题