4

a UIView is created and small snow.png is kept added and removed to UIView to simulate the snowing effect.

Then I would like to capture the screen as an image.

UIGraphicsBeginImageContext(self.uiviewPreview.bounds.size);
[self.uiviewPreview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Note: self.uiviewPreview is the UIView.

But I can only see the image in UIview in the saved jpg. But all added subviews at that moment are not saved.

I would like to know whether renderInContext is correct or not to use

TomH
  • 2,950
  • 2
  • 26
  • 49
SkyEagle888
  • 1,009
  • 2
  • 18
  • 42

1 Answers1

1

It's the right method and it should work.

Note that the method has one big flaw, it doesn't reflect the actual state of layer animations (alpha, autoresizing, repositioning etc.). If you are drawing the layer while animating it, it won't work.

Sulthan
  • 128,090
  • 22
  • 218
  • 270