Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load image from documents directory/IPHONE
    primarykey
    data
    text
    <p>I am saving the images when there is internet connection in my iphone. Now i want to load the images which are saved in documents directory. I am getting the path, but the image is not displaying. Please help me in this. Thanks in advance.</p> <p>Here is my code:</p> <pre><code>+(UIImage *) getImagewithName:(NSString*) imagepath { NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; UIImage *gimage=[UIImage imageWithContentsOfFile: [NSString stringWithFormat:@"%@/%@",docDir,imagepath]]; NSLog(@"%@/%@",docDir,imagepath); return gimage; } +(void)DownloadImage:(NSString*)ImagePath { if ([ImagePath isEqualToString:@""]) return; UIImage *dimage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:/uploads/%@",ImagePath]]]]; NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSLog(@"pathIMAGEPATHS:::::::%@",ImagePath); NSLog(@"path:::::::%@",docDir); NSArray *patharr=[ImagePath componentsSeparatedByString:@"."]; NSString* Ext=[NSString stringWithFormat: @"%@",[patharr objectAtIndex:1]]; NSString *FilePath = [NSString stringWithFormat: [NSString stringWithFormat:@"%@/%@",docDir,ImagePath]]; if([Ext isEqualToString:@"png"]) { NSLog(@"saving png"); NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(dimage)]; [data1 writeToFile:FilePath atomically:YES]; } else if([Ext isEqualToString:@"jpeg"]) { NSLog(@"saving jpeg"); //NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpeg",docDir]; NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(dimage, 1.0f)];//1.0f = 100% quality [data2 writeToFile:FilePath atomically:YES]; } else { NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(dimage)]; [data1 writeToFile:FilePath atomically:YES]; } NSLog(@"saving image done"); [dimage release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload