zoukankan      html  css  js  c++  java
  • iOS 图片的存储以及读取和删除

    将图片存储到本地

     NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
                NSString *path = [dirArray firstObject];
                path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",_selectIndex]];
                NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
                [imageData writeToFile:path atomically:YES];

    图片的存到本地之后的读取

     NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
            NSString *path = [dirArray firstObject];
            path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",i]];
            if([[NSFileManager defaultManager] fileExistsAtPath:path]){
                NSData *picData = [NSData dataWithContentsOfFile:path];
                view.idCardImageView.image = [UIImage imageWithData:picData];
                }

    将存储到本地的图片删除

     NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
            NSString *path = [dirArray firstObject];
            path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",i]];
            if([[NSFileManager defaultManager] fileExistsAtPath:path])//如果存在临时文件的配置文件
            {
                [[NSFileManager defaultManager]  removeItemAtPath:path error:nil];
            }
  • 相关阅读:
    自动化测试成功11333
    自动化测试成功11222
    自动化测试成功1111
    自动化测试成功112
    自动化测试成功18
    自动化测试成功1
    自动化测试成功
    富文本测试
    关于VMware虚拟机磁盘收缩的几种方法
    8个让你更有效率的简单方法
  • 原文地址:https://www.cnblogs.com/carlos-mm/p/5797925.html
Copyright © 2011-2022 走看看