uiimageios7calayercgcontextref

iOS7 screenshot not taking into consideration blur effect


I'm taking screen shot with this code

- (UIImage *)screenshot {
    UIGraphicsBeginImageContext(self.bounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

but the resulting image doesn't have the alpha and blur effects showing properly

any way to fix this?


Solution

  • When you look into the documentation of "renderInContext" you can see it has some downsides when it comes to Animations and so one. Try it with this, if it isn't necessary to take a screenshot of the layer directly

    - (UIImage *)screenshot {
        UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 0);
        [self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:NO];
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
    }