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

            }

     

     

     

     

  • 相关阅读:
    几个容易混淆的集合类
    ajax操作时用于提高用户体验的两段备用代码
    word-wrap和word-break的区别
    清除MAC OS X上的流氓软件
    Windows Azure IP地址详解
    实现跨云应用——基于DNS的负载均衡
    Windows Azure虚拟机和云服务实例计费方式更新
    证明你是你——快速开启Windows Azure多重身份验证
    Windows 10 L2TP 809错误
    新版Microsoft Azure Web管理控制台
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5231419.html
Copyright © 2011-2022 走看看