当前位置: 代码迷 >> 综合 >> iOS屏幕截图
  详细解决方案

iOS屏幕截图

热度:48   发布时间:2024-01-20 19:51:46.0

//获得屏幕图像  

  • - (UIImage *)imageFromView: (UIView *) theView    
  • {  
  •     UIGraphicsBeginImageContext(theView.frame.size);  
  •     CGContextRef 

context = UIGraphicsGetCurrentContext();  

  •     [theView.layer renderInContext:context];  
  •     UIImage *

theImage= UIGraphicsGetImageFromCurrentImageContext();  

  •     UIGraphicsEndImageContext();       
  •     return theImage;  
  • }  
  •  
  • //获得某个范围内的屏幕图像  
  • - (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r  
  • {  
  •     UIGraphicsBeginImageContext(theView.frame.size);  
  •     CGContextRef 

context= UIGraphicsGetCurrentContext();  

  •     CGContextSaveGState(context);  
  •     UIRectClip(r);  
  •     [theView.layer renderInContext:context];  
  •     UIImage *

theImage= UIGraphicsGetImageFromCurrentImageContext();  

    UIGraphicsEndImageContext();  

  •     return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];  
  • } 
  相关解决方案