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

            }

     

     

     

     

  • 相关阅读:
    0625jQuery练习:权限基础1:查询员工对应角色、修改员工对应角色
    0624jQuery练习:三级联动—时间
    0622jQuery基础:常用属性
    0621jQuery基础:基础属性
    0621jQuery练习:三级联动
    0621jQuery练习:弹窗
    0621jQuery基础:事件
    数据库连接-登录
    javaScript中的DOM操作及数组的使用
    设置日期对象(年-月-日 时-分-秒)实现菱形的拼接
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5231419.html
Copyright © 2011-2022 走看看