UIImage screenshot loses its quality

前端 未结 5 1394
再見小時候
再見小時候 2020-12-11 09:37

I am merging two images and then I take a screenshot by applying this code:

UIGraphicsBeginImageContext(size);
[self.view.layer renderInContext:UIGraphicsGet         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 10:19

    I've made a category on UIImage class that may help you. It goes like this:

    + (UIImage*)imageWithView:(UIView *)view opaque:(BOOL)opaque bgColor:(UIColor*)bgColor{
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, opaque, [[UIScreen mainScreen] scale]);
    
        if(!opaque){
            [bgColor set];
        }
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }
    

    It works fine for me. No bluring was detected. Try to use it. If you'll still have it then most likely the problem is in your saving code...

    Cheers... :)

提交回复
热议问题