Iphone : How to Display Document Directory images in Image View?

sample code:

- (NSString *)applicationDocumentsDirectory {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

-(void)loadimage{
    NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"your image-name"];
    UIImageView *myimage=[UIImageView alloc] initWithFrame:CGRectMake(0,0,20,20)];
    myimage.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    
    [self.view addSubView:myimage];
    [myimage release];
}

TNQ


You can achieve it, By knowing the names of your images, so while you are storing your image you need to store some information of these images in database,(or some where you can use it), then fetch name of image from data source, and work as follows:

NSString *str = [NSString stringWithFormat:@"%@.jpg",[myGlobleArrayOfImageNames objectAtIndex:imageCounter]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullImgNm=[documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:str]];
[mainSlideShowImageView setImage:[UIImage imageWithContentsOfFile:fullImgNm]];

Here you can take UIImageView in your View and add it to the view and do the same like as follows:

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

imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"image1.png"];

 UIImageView *objImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
 objImageView.image = [UIImage imageWithContentsOfFile: imageFilePath];
 [self.view addSubVIew:objImageView.image];
 [objImageView release];

Please let me know if you still need any help.


NSArray *directoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *imagePath =  [directoryPath objectAtIndex:0];
imagePath= [imagePath stringByAppendingPathComponent:@"imagename.png"];

 NSData *data = [NSData dataWithContentsOfFile:imagePath];
    UIImage *img = = [UIImage imageWithData:data];

you can display this image to uiimageview