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

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

你可能感兴趣的:(将图片保存在本地沙盒路径下)