您的位置:首页 > 移动开发 > IOS开发

IOS开发之—程序截图

2014-02-14 14:55 134 查看
//获得屏幕图像  

- (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];
 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS uiimage uiview