【问题标题】:ios capture screenshot, but there is a blank(transparent) on the top, it is the status-barios截屏,但顶部有一个空白(透明),它是状态栏
【发布时间】:2012-12-04 01:42:44
【问题描述】:

屏幕截图,960*640,但图片顶部有 44pix 透明状态栏。

如何拍摄 916pix 高度的图片?我不需要顶部的那个空白栏。

这是我的代码:

-(void)takeScreenShot{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f);
    }else{
        UIGraphicsBeginImageContext(imageSize);
    }
    [window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData * data = UIImagePNGRepresentation(image);
    //
    NSString *documentsDirectory= [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *filePath= [documentsDirectory stringByAppendingPathComponent:@"SYS_screen_shot@2x.png"];
    //
    [data writeToFile:filePath atomically:YES];
}

【问题讨论】:

    标签: ios screenshot statusbar


    【解决方案1】:

    您可以使用此访问应用程序框架 [[UIScreen mainScreen] applicationFrame]
    这将为您提供应用程序在屏幕上的位置


    [window.rootViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    如果您想要的是您的应用程序的root view,您应该将该视图带到renderInContext。我刚刚测试了它,它可以工作。

    【讨论】:

      猜你喜欢
      • 2018-10-13
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 2017-01-10
      • 2015-10-28
      • 2014-08-19
      相关资源
      最近更新 更多