2012-05-18 40 views
0
檢索的UIImage文件目錄

我已經使用這個函數的本地存儲圖像文件的目錄中創建如何從特定文件夾中的iPhone

NSError *error; 
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString* documentsDirectory = [paths objectAtIndex:0]; 

// FOR STORING IMAGE INTO FOLDER CREATED IN DOCUMENT DIRECTORY 

NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ImagesFolder"];  
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) 
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; 

NSData* imageData = UIImagePNGRepresentation(imageView.image); 
NSString* incrementedImgStr = [NSString stringWithFormat:@"Image%d.png",delegate.dirCountImages]; 
NSString* fullPathToFile2 = [dataPath stringByAppendingPathComponent:incrementedImgStr]; 
[imageData writeToFile:fullPathToFile2 atomically:NO]; 

但是我如何檢索特定文件夾的圖像在一個文件夾中文件目錄

回答

0
-(NSMutableArray*)getPhotoFileNames:(NSString*)parentFolderName 
{ 
NSString *path = [NSString stringWithFormat:@"%@/%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)objectAtIndex:0], parentFolderName]; 

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; 
NSEnumerator *enumerator = [dirContents objectEnumerator]; 
id fileName; 
NSMutableArray *fileArray = [[NSMutableArray alloc] init]; 
while (fileName = [enumerator nextObject]) 
{ 
    NSString *fullFilePath = [path stringByAppendingPathComponent:fileName]; 
    NSRange textRangeJpg = [[fileName lowercaseString] rangeOfString:[@".png" lowercaseString]]; 

    if (textRangeJpg.location != NSNotFound) 
    { 
     UIImage  *originalImage = [UIImage imageWithContentsOfFile:fullFilePath]; 
     [fileArray addObject:originalImage]; 
    } 
} 
return fileArray; 
} 
0

只需要有完整的路徑和使用此方法。 [[UIImage alloc]initWithContentsOfFile: <#path#>]如果您不使用ARC,請記住釋放圖像。

0

也許這會幫助你。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Images"]; 
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"Image.png"]; 
[cell.songImageView setImage:[UIImage imageWithContentsOfFile:documentsDirectory]]; 
相關問題