29,027
社区成员
发帖
与我相关
我的任务
分享
NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"photo" ofType:@"jpg"]];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
//写入100张图片到沙盒中,观察内存
for (int i=0; i<100; i++) {
NSString *photoPath=[path stringByAppendingPathComponent:[NSString stringWithFormat:@"photo_%zi",i]];
UIImage *image = [[UIImage alloc] initWithData:data];
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];
}
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];
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];
image=nil;
}
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]];
@autoreleasepool {
UIImage *image = [[UIImage alloc] initWithData:data];
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];
}
}