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


    图片 写入沙盒

        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];

            }

     

     

     

     

  • 相关阅读:
    小程序-自定义组件
    51Nod
    CodeForces
    JSON、闭包和原型----透视Javascript语言核心
    转载:动态规划法总结
    to初学者:从汉诺塔问题深入理解递归算法思想
    不知‘时间复杂度’所云的看过来
    盲点流水账记录
    常用序列化协议总结
    排序——了解总体以及插入排序
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5231419.html
Copyright © 2020-2023  润新知