I've blurred my view programmatically and added a share extension with screenshot but the screenshot doesn't blur my view in the image. All programming in swift
Code for blurring
let blurEffect = UIBlurEffect(style:.Dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = imageView2.frame
self.view.addSubview(blurView)
Code for screenshot
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Thanks
Try taking the screenshot this way:
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
I just found Apple has actually documented on how to take a snapshot of UIVisualEffectView:
Capturing a Snapshot of a UIVisualEffectView 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.
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With