0

スクリーンショット、960*640、ただし 44pix の透明ステータスバー付き

スクリーンショット、960*640 ですが、画像の上部に 44 ピクセルの透明なステータス バーがあります。

高さ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];
}
4

1 に答える 1

0

You have access to the application frame with this [[UIScreen mainScreen] applicationFrame]
That will give you the position of your application on the screen


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

If what you want is the root view of your application, you should take that view to renderInContext. I just tested it and it work.

于 2012-12-04T02:00:40.563 に答える