ios 抓图实现

来源:互联网 发布:mindmap mac 编辑:程序博客网 时间:2024/06/05 00:20
  1. //获得屏幕图像  
  2. (UIImage *)imageFromView: (UIView *) theView    
  3. {  
  4.       
  5.     UIGraphicsBeginImageContext(theView.frame.size);  
  6.     CGContextRef context UIGraphicsGetCurrentContext();  
  7.     [theView.layer renderInContext:context];  
  8.     UIImage *theImage UIGraphicsGetImageFromCurrentImageContext();  
  9.     UIGraphicsEndImageContext();  
  10.       
  11.     return theImage;  
  12. }  
  13.  
  14. //获得某个范围内的屏幕图像  
  15. (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r  
  16. {  
  17.     UIGraphicsBeginImageContext(theView.frame.size);  
  18.     CGContextRef context UIGraphicsGetCurrentContext();  
  19.     CGContextSaveGState(context);  
  20.     UIRectClip(r);  
  21.     [theView.layer renderInContext:context];  
  22.     UIImage *theImage UIGraphicsGetImageFromCurrentImageContext();  
  23.     UIGraphicsEndImageContext();  
  24.       
  25.     return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];  
0 0
原创粉丝点击