nicklockwood / FXBlurView

[DEPRECATED]
Other
4.94k stars 713 forks source link

Issues with trying to take a screenshot of a view with an FXBlurView on top. #123

Closed Umar-M-Haroon closed 8 years ago

Umar-M-Haroon commented 8 years ago

I have a section of my app that contains a blurred image, and if you try to save the image with the following code, the blur will result in lots of squares, which is not aesthetically appealing.

Here is the following code for taking the screenshot

{

    UIView *wholeScreen = self.pictureView;

    // define the size and grab a UIImage from it
    UIGraphicsBeginImageContextWithOptions(wholeScreen.bounds.size, wholeScreen.opaque, 0.0);
    [wholeScreen.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(screengrab, nil, nil, nil);

}
nicklockwood commented 8 years ago

Try capturing the screenshot using -[UIView drawViewHierarchyInRect:afterScreenUpdates:] instead.

Umar-M-Haroon commented 8 years ago

Adding [wholeScreen.layer drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]; fixes the issue. Closing now.