图片写入沙盒 读取图片 删除图片

图片 写入沙盒

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSInteger photoNumber = [SingleClass sharedGlobal].photoNumber;

    NSString * photoStr = [NSString stringWithFormat:@"saveImage_%ld.png",photoNumber];

    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:photoStr];

     [UIImagePNGRepresentation(saveImage) writeToFile:filePath atomically:YES];

 

获取图片地址

    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSInteger photoNumber = [SingleClass sharedGlobal].photoNumber;

    NSString * photoStr = [NSString stringWithFormat:@"saveImage_%ld.png",photoNumber];

    NSString *path = [[array objectAtIndex:0] stringByAppendingPathComponent:photoStr];

    NSLog(@"button显示的图片地址+++%@",path);

    UIImage *image = [UIImage imageWithContentsOfFile:path];

删除图片

        for (NSInteger i = 0; i < 5; i++) {

            NSFileManager* fileManager=[NSFileManager defaultManager];

            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

            NSString * photoStr = [NSString stringWithFormat:@"saveImage_%ld.png",i];

            NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:photoStr];

            BOOL ifHave = [fileManager fileExistsAtPath:filePath];

            if (!ifHave) {

                continue; // 开始 下次循环

            }

            [fileManager removeItemAtPath:filePath error:nil];

            [imageCollectionV reloadData];

        }

 

 

 

 

posted @ 2016-03-01 16:11  徒步阳光855  阅读(200)  评论(0编辑  收藏  举报