如何拍摄916像素高的照片?我顶部不需要那个空白栏。
这是我的代码:
-(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];
}
答案 0 :(得分:0)
您可以使用此权限访问应用程序框架
[[UIScreen mainScreen] applicationFrame]
这将为您提供应用程序在屏幕上的位置
[window.rootViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
如果你想要的是你的应用程序的root view
,你应该将该视图带到renderInContext
。我只是测试了它并且它有效。