iOS屏幕截图

//获得屏幕图像  

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

context = UIGraphicsGetCurrentContext();  

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

theImageUIGraphicsGetImageFromCurrentImageContext();  

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

contextUIGraphicsGetCurrentContext();  

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

theImageUIGraphicsGetImageFromCurrentImageContext();  

    UIGraphicsEndImageContext();  

  •     return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];  

你可能感兴趣的:(ios,图片,图形,2d)