Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screenshot programmatically and blur in Swift

I want to take a screenshot from my app programmatically and the code working fine but I have a UIVisualEffectView with blur effect and the screenshot gave me the image without blur! How I can make the screenshot take the blur also?

UIGraphicsBeginImageContextWithOptions(fullView.bounds.size, true, 1)
self.fullView.layer.renderInContext(UIGraphicsGetCurrentContext())
var viewImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil)
like image 774
BandarAljahmi Avatar asked Mar 17 '23 19:03

BandarAljahmi


1 Answers

To retain the UIVisualEffectView Blur when taking an image of the screen programmatically, you must be taking an image of the entire screen.

Here is a more technical definition provided by Apple:

Many effects require support from the window that hosts the UIVisualEffectView. Attempting to take a snapshot of only the UIVisualEffectView will result in a snapshot that does not contain the effect. To take a snapshot of a view hierarchy that contains a UIVisualEffectView, you must take a snapshot of the entire UIWindow or UIScreen that contains it. - Apple Documentation

like image 108
user3721428 Avatar answered Mar 31 '23 19:03

user3721428