美文网首页
将图片保存在本地沙盒路径下

将图片保存在本地沙盒路径下

作者: 成语笔记 | 来源:发表于2016-08-30 13:59 被阅读15次

    NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"photo" ofType:@"jpg"]];

    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

    for (int i=0; i<100; i++) {

    NSString *photoPath=[path stringByAppendingPathComponent:[NSString stringWithFormat:@"photo_%zi",i]];

    UIImage *image = [[UIImage alloc] initWithData:data];

    NSData *data1 = UIImagePNGRepresentation(image);

    [data1 writeToFile:photoPath atomically:YES];

    data1 = nil;

    image=nil;

    }

    data = nil

    相关文章

      网友评论

          本文标题:将图片保存在本地沙盒路径下

          本文链接:https://www.haomeiwen.com/subject/tuwfettx.html