2013-01-21 58 views
0

我想救我的設備以這種方式以後使用的截圖:加載保存的UIImage

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; 

我該怎麼辦?

回答

2

[UIImage imageNamed:]用於加載已包含在應用程序包中的圖像。

假設你的路徑是正確的,你可以通過

UIImage *image = [UIImage imageWithContentsOfFile: pngPath]; 
加載