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

            }

     

     

     

     

  • 相关阅读:
    [leetcode]Set Matrix Zeroes
    [leetcode]Sort Colors
    [leetcode]Combinations
    [leetcode]Subsets
    [leetcode]Search a 2D Matrix
    [leetcode]Best Time to Buy and Sell Stock III
    [leetcode]Best Time to Buy and Sell Stock II
    [leetcode]Best Time to Buy and Sell Stock
    半平面交 (poj 1279(第一道半平面NlogN)完整注释 )
    hdu 4277 USACO ORZ (Dfs)
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5231419.html
Copyright © 2011-2022 走看看