ios截图代码

来源:互联网 发布:保山学院网络教学平台 编辑:程序博客网 时间:2024/06/13 06:31
    CGRect cutRect = CGRectMake(0, 0, _imageView.frame.size.width, _imageView.frame.size.width);  //截图矩形
    UIGraphicsBeginImageContextWithOptions(cutRect.size, YES, 0.0);  //创建基于当前上下文
    [_imageView.layer renderInContext:UIGraphicsGetCurrentContext()]; //渲染,这里是截取imageview显示的图片,如果是截屏则此处是self.view.layer
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();  //要释放上下文,否则内存泄露
0 0