iOS截屏方法

//获取屏幕截屏方法
- (UIImage *)capture
{

    // 创建一个context
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);

    //把当前的全部画面导入到栈顶context中并进行渲染
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    // 从当前context中创建一个新图片
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    // 使当前的context出堆栈
    UIGraphicsEndImageContext();

    return img;
}
posted @ 2016-02-27 18:09  专注it  阅读(156)  评论(0编辑  收藏  举报