iOS View生成--->清晰的圖片


核心代碼

view生成圖片方法

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

生成的清晰圖片

#pragma mark 生成image  
- (UIImage *)GetmakeImageWithView:(UIView *)view andWithSize:(CGSize)size  
{  
      
    // 下面方法,第一個參數表示區域大小。第二個參數表示是否是非透明的。如果需要顯示半透明效果,需要傳NO,否則傳YES。第三個參數就是屏幕密度了,關鍵就是第三個參數 [UIScreen mainScreen].scale。  
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);  
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];  
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
    return image;  
  
}  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM