iOSでスクリーンショットを撮る方法
2019.11.25
2019.11.25
質問内容
画面上の画像のスクリーンショットを保存済みの写真ライブラリに保存したい。
ベストアンサー
Retinaディスプレイのチェックを検討する場合は、次のコードスニペットを使用します。
#importif ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale); } else { UIGraphicsBeginImageContext(self.window.bounds.size); } [self.window.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *imageData = UIImagePNGRepresentation(image); if (imageData) { [imageData writeToFile:@"screenshot.png" atomically:YES]; } else { NSLog(@"error while taking screenshot"); }
原文
https://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically-on-ios