【问题标题】:xcode: trying to capture a partial screenxcode:尝试捕获部分屏幕
【发布时间】:2012-05-24 15:02:06
【问题描述】:

我一定是做错了什么,但我可以在以下方面提出一些建议:

我正在尝试在 iPad 和 iPad Retina 上捕获部分屏幕。

我可以让纵向视图正常,但我不能让横向视图的右侧进入边界。

这是我正在使用的代码(在 UIGetScreenImage() 成为违禁品之前我没有遇到这个问题)..

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
[[UIColor blackColor] set]; 
CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake (0, 100, self.view.bounds.size.width, (self.view.bounds.size.height - 200)));


UIImage *img2Save = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Request to save the image to camera roll
UIImageWriteToSavedPhotosAlbum(img2Save, self, nil, nil);

这是我拍到的两张纵向和横向图片:

【问题讨论】:

    标签: graphics xcode4 screenshot


    【解决方案1】:

    如果您将窗口用作框架,它将始终以纵向模式显示。您可以将 screenRect 设置为全屏视图,它应该在纵向和横向模式下都可以工作。

    【讨论】:

    • 谢谢。我正在谷歌搜索和搜索..你有一个首选的方法来设置这个。我能找到的最好的方法是检查方向,并手动设置坐标。大卫
    • 我发现这篇 SO 帖子 - stackoverflow.com/questions/5677716/… 给了我更好的便利方法。但是你把我引向了正确的方向,我非常感激。所以我将其标记为关闭.. 再次感谢您。
    猜你喜欢
    • 2016-02-13
    • 2020-10-28
    • 1970-01-01
    • 2016-03-28
    • 2011-12-16
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    • 2012-05-16
    相关资源
    最近更新 更多