将 UIView 捕获为 UIImage
我一直在使用这种方法将 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
的图像表示。现在我想要两张图像,一张是 UIView 的上半部分,另一张是下半部分。我该怎么做?
I have been using this method to convert a UIView
into UIImage
. i.e. screen snapshot of a view -
@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
To use it, I do this -
UIImage *currImage = [self.view imageByRenderingView];
This gives the image representation of the entire UIView
. Now I want 2 images, one is of the top half of the UIView
and the other is the bottom half. How do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下代码将
UIImage
一分为二:You can split your
UIImage
in two by using this code: