【发布时间】:2014-09-14 11:54:37
【问题描述】:
我正在截取我的视图并将其存储在文档目录中。但我需要在 iphone 图库应用中显示存储的图像。我不知道如何将图像传递到画廊视图。 在这方面帮助我。 谢谢你的建议。。
- (IBAction)Screenshot:(id)sender {
CGSize targetImageSize = CGSizeMake(500, 500);
// Check for retina image rendering option
if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(targetImageSize, NO, 0);
else UIGraphicsBeginImageContext(targetImageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// The view to be rendered
[[image layer] renderInContext:context];
// Get the rendered image
UIImage *original_image = UIGraphicsGetImageFromCurrentImageContext();
NSLog(@"%@",original_image);
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/screenshots"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
//Create folder
// NSString *documentsDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/myPngFile.png",dataPath];
[UIImagePNGRepresentation(original_image) writeToFile:pngFilePath atomically:YES];
//[_image1 setImage:original_image];
UIGraphicsEndImageContext();
}
【问题讨论】:
标签: objective-c iphone ios7 nsdocumentdirectory