How to capture UIView to UIImage without loss of quality on retina display

前端 未结 17 1758
时光取名叫无心
时光取名叫无心 2020-11-22 00:42

My code works fine for normal devices but creates blurry images on retina devices.

Does anybody know a solution for my issue?

+ (UIImage *) imageWith         


        
17条回答
  •  长发绾君心
    2020-11-22 01:03

    - (UIImage*)screenshotForView:(UIView *)view
    {
        UIGraphicsBeginImageContext(view.bounds.size);
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        // hack, helps w/ our colors when blurring
        NSData *imageData = UIImageJPEGRepresentation(image, 1); // convert to jpeg
        image = [UIImage imageWithData:imageData];
    
        return image;
    }
    

提交回复
热议问题