截图

来源:互联网 发布:淘宝客服绩效考核标准 编辑:程序博客网 时间:2024/04/26 19:11
+ (UIImage *) imageFromView: (UIView *) theView 



    //Draw a view`s contents into an image context 

    UIGraphicsBeginImageContext(theView.frame.size); 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    [theView.layer renderInContext:context]; 

    UIGraphicsEndImageContext(); 

    return theImage; 



--此函数要用到QuartzCore.framework框架 


//获得某个范围内的屏幕图像  
- (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];  
}
原创粉丝点击