0

我有几个 UIImageViews 在其他的上面,可以说我想将它们全部保存一个图像。有没有办法“截图”/将所有 UIImageView 连接到一个?

那么我可以使用:

UIGraphicsBeginImageContext(mv.frame.size);
[[mv layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

谢谢你。

4

2 回答 2

1

您可以通过制作有关 all 的超级视图的屏幕截图来做到这一点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;
    }
于 2013-10-14T10:05:10.997 回答
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];

祝你好运!!

于 2013-10-14T10:11:06.607 回答