开发者

Save image to device

开发者 https://www.devze.com 2023-01-30 06:10 出处:网络
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]]]];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消