Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In a App images stored in Document Directory Folder,

I wanted Particular image display in Image view,

How that image Display in Image View from the Document Directory ?

like image 515
Ankit Chauhan Avatar asked Jul 12 '11 11:07

Ankit Chauhan


2 Answers

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

like image 197
TalaT Avatar answered Oct 12 '22 00:10

TalaT


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

like image 38
Dinakar Avatar answered Oct 12 '22 01:10

Dinakar