Reputation: 1533
I have a couple of UIImageViews on top of eace other, lets say i want to save all of them a single image. Is there a way to "screenshot"/ connect all of the UIImageView to one ?
So then i could use:
UIGraphicsBeginImageContext(mv.frame.size);
[[mv layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Thank You.
Upvotes: 0
Views: 58
Reputation: 1614
if you want a fast and easy approach take a screenshot of the view that holds your images
- (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; }
and get it with:
UIImage *screenshot = [self screenShot:self.view];
Good Luck!!
Upvotes: 1
Reputation: 4272
You can do it by making a screenshot about the superview of all UIImageView
. I wrote a method for this: (be sure you added your UIImageViews
to the same view. for example:
[self.view addSubview: image1];
[self.view addSubview: image2];
[self.view addSubview: image3];
[self.view addSubview: image4];
then make a screenshout about 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;
}
Upvotes: 1