我有一些UIImageViews在eace之上,让我们说我想要保存所有这些单个图像。 有没有办法将所有UIImageView“截屏”/连接到一个?
那么我可以使用:
UIGraphicsBeginImageContext(mv.frame.size);
[[mv layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
谢谢。
答案 0 :(得分:1)
您可以通过制作有关所有UIImageView
的超级视图的屏幕截图来完成此操作。我为此写了一个方法:(确保将UIImageViews
添加到同一视图中。例如:
[self.view addSubview: image1];
[self.view addSubview: image2];
[self.view addSubview: image3];
[self.view addSubview: image4];
然后制作关于self.view
的屏幕截图
)
+ (UIImage*) screenShotTheArea:(CGRect)area inView:(UIView*)view{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(CGSizeMake(area.size.width, area.size.height), NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, -area.origin.x, -area.origin.y);
[view.layer renderInContext:c];
UIImage* thePrintScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return thePrintScreen;
}
答案 1 :(得分:1)
如果您想要快速简便的方法,请截取包含图像的视图
- (UIImage *)screenShot:(UIView *)aView {
UIGraphicsBeginImageContext(self.view.frame.size);
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGContextSetRGBFillColor (UIGraphicsGetCurrentContext(), 0, 0, 0, 0.4f);
CGContextFillRect (UIGraphicsGetCurrentContext(), self.view.frame);
UIGraphicsEndImageContext();
return image; }
并获得:
UIImage *screenshot = [self screenShot:self.view];
祝你好运!!