我正在截取我的視圖並將其存儲在文檔目錄中。但我需要在iphone畫廊應用程序中顯示存儲的圖像。我不知道如何將圖像傳遞到圖庫視圖。 幫助我。 感謝ü在進階..如何顯示存儲在文檔目錄中的圖像到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();
}
u救了我的一天(Y) –
@muthukumaresh你應該接受答案並讓別人知道它工作正常 –