將圖片儲存在本地沙盒路徑下

weixin_33728268發表於2016-08-30

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

相關文章