zoukankan      html  css  js  c++  java
  • 图片写入沙盒 读取图片 删除图片

    图片 写入沙盒

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

            }

     

     

     

     

  • 相关阅读:
    接口框架项目示例
    接口框架开发流程总结
    requests库的简单使用
    使用flask创建简单的接口
    session和token
    解决log函数生成重复log的问题
    自定义封装logging参考
    织梦dedecms做的网站首页标题篡改跳转赌博网站解决方案
    织梦网站安全查杀
    织梦重置密码的方法和织梦网站后台登陆账号修改方法
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5231419.html
Copyright © 2011-2022 走看看