iOS View generation ---> clear picture

core code

View generating image method

UIGraphicsBeginImageContext(view.bounds.size);  
   [view.layer renderInContext:UIGraphicsGetCurrentContext()];  
   UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();  
   UIGraphicsEndImageContext();  

Generate clear pictures

#pragma mark generate image  
- (UIImage *)GetmakeImageWithView:(UIView *)view andWithSize:(CGSize)size  
{  
      
    // The following method, the first parameter indicates the area size. The second parameter indicates whether it is non-transparent. If you need to display the translucent effect, you need to pass NO, otherwise pass YES. The third parameter is the screen density, and the key is the third parameter [UIScreen mainScreen].scale.  
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0 );  
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];  
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    return image;  
  
}  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325696386&siteId=291194637