屏幕截图,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];
}