NSDocumenDirectory
我的储蓄有奇怪的问题。这是一个预览:首先我选择图像(在我的imagePickerViewController
):
在我的PreviewController
:
所以第一次尝试,没问题。
然后我重新访问imagePickerViewController
添加另一个图像:
在我的PreviewController
:
这就是问题发生的地方。在上图中,它从旧预览中重新复制了最后一张图像(如副本)。我不知道我在我的代码中做错了什么。但是当文件存在时我会保存它。请看:
for (int i = 0; i < info.count; i++) {
NSLog(@"%@", [info objectAtIndex:i]);
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"firstSlotImages%d.png", i]];
if ([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]) {
NSLog(@"file doesnt exist");
} else {
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
//----resize the images
image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
NSLog(@"saving at:%@",savedImagePath);
}
}
我需要的是用新的图像重新添加相同的图像。和上次预览一样。