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

前端 未结 17 1490
时光取名叫无心
时光取名叫无心 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:04

    In this method just pass a view object and it will returns a UIImage object.

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

提交回复
热议问题