我正在尝试以这种方式保存我的设备的屏幕截图以供以后使用:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:@"background55667.png"];
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/background55667.png";
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
...但我似乎无法打开它并在 UIImageView 中显示它。像这样的东西:
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
// Write out the contents of home directory to console
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
UIImage *image = [UIImage imageNamed:....];
backGroundPhoto.image = image;
我该怎么做?