Save image to device
Hi i cant seem to get his code to work
//Save Image To Device
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[self.ImageURLS objectAtIndex:0]]]];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"saving jpg");
NSString *jpgFilePath = [NSString stringWithFormat:@"%@/%@.jpg",docDir,[self.NameArray objectAtIndex:0]];
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
[data2 writeToFile:jpgFilePath atomically:YES];
and i am getting the image via
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *jpgFilePath = [NSString stringWithFormat:@"%@/%@.jpg",docDir,[self.NameArray objectAtIndex:[indexPath row]]];
UIImage *image = [UIImage imageN开发者_StackOverflow中文版amed:jpgFilePath];
Any help ?
Thanks
Change the last line of your code to
UIImage *image = [UIImage imageWithContentsOfFile:jpgFilePath];
UIImage's +imageNamed:
searches the app bundle for a file with a given name, which is not what you need.
精彩评论