문제

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?

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top