首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >超出屏幕界限的屏幕截图

超出屏幕界限的屏幕截图
EN

Stack Overflow用户
提问于 2014-02-25 14:15:15
回答 1查看 60关注 0票数 0

我使用UIGraphicsBeginImageContextWithOptions来获取当前显示的屏幕(UITable)的屏幕抓取。

这是我的密码:

代码语言:javascript
复制
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

然后,我使用图像对象作为屏幕抓取。

我的问题是,我希望屏幕抓取包括额外的100像素当前未显示的数据(如果我向下滚动它将显示)。

我怎么能这么做?

EN

回答 1

Stack Overflow用户

发布于 2014-02-25 14:27:22

代码语言:javascript
复制
- (IBAction) renderScrollViewToImage
 {
   UIImage* image = nil;

   UIGraphicsBeginImageContext(_scrollView.contentSize);
  {
    CGPoint savedContentOffset = _scrollView.contentOffset;
    CGRect savedFrame = _scrollView.frame;

    _scrollView.contentOffset = CGPointZero;
    _scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);

    [_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];     
    image = UIGraphicsGetImageFromCurrentImageContext();

    _scrollView.contentOffset = savedContentOffset;
    _scrollView.frame = savedFrame;
   }
  UIGraphicsEndImageContext();

if (image != nil) {
    [UIImagePNGRepresentation(image) writeToFile: @"/tmp/test.png" atomically: YES];
    system("open /tmp/test.png");
  }
}

参考link

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22016782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档