iOS 沙盒图片的存取

server/2024/9/23 2:27:40/
简介:

图片的沙盒读存操作主要是增、删、查,一般不涉及改的操作,这里直接以代码演示

常用代码:
  1.  /***  存储缩略图到沙盒中*/+ (BOOL)saveImageToPath:(NSString *)imageFilePath image:(UIImage *)image{return [UIImageJPEGRepresentation(image, 0.5) writeToFile:imageFilePath  atomically:YES];}
    
  2.  /***  删除沙盒里的缩略图*/+ (void)deleteImageWithPath:(NSString *)thumbnailPath{BOOL isHave = [[NSFileManager defaultManager] fileExistsAtPath:thumbnailPath];if (!isHave) {NSLog(@"no  have");return ;}else {NSError *error;BOOL isDeleteFinish = [[NSFileManager defaultManager] removeItemAtPath:thumbnailPath error:&error];if (!isDeleteFinish) {NSLog(@"delete fail --- %@", error);}}}
    
  3.  UIImage *image = [UIImage imageWithContentsOfFile:thumbnailPath];
    
  4. 获取缩略图路径

     /***  获取缩略图的路径*/+ (NSString *)getFilePath{NSString *libPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];NSString *thumbnailPath = [NSString stringWithFormat:@"%@/Caches/AR/ARThumbnail", libPath];NSFileManager *fileManager = [NSFileManager defaultManager];if (![fileManager fileExistsAtPath:thumbnailPath]) {NSError *error;[fileManager createDirectoryAtPath:thumbnailPath withIntermediateDirectories:YES attributes:nil error:&error];if (error) {NSLog(@"error");return nil;}}        return thumbnailPath;}
    
  5. 获取沙盒根目录
    //获取沙盒根目录
    NSString *directory = NSHomeDirectory();
    NSLog(@“directory:%@”, directory);

  6. 获取Document路径
    //获取Documents路径
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSLog(@“path:%@”, path);

  7. 获取Library路径

      //获取Library路径NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);NSString *path = [paths objectAtIndex:0];NSLog(@"path:%@", path);
    
  8. 获取tmp路径

      NSString *tmp = NSTemporaryDirectory();NSLog(@"tmp:%@", tmp);
    
  9. 获取Caches路径

      //获取Caches路径NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);NSString *path = [paths objectAtIndex:0];NSLog(@"path:%@", path);
    

http://www.ppmy.cn/server/39546.html

相关文章

GitLab CI/CD的原理及应用详解(一)

本系列文章简介: 在当今快速变化的软件开发环境中,持续集成(Continuous Integration, CI)和持续交付(Continuous Delivery, CD)已经成为提高软件开发效率、确保代码质量以及快速响应市场需求的重要手段。Gi…

IIS配置SSL,根据pem和key生成pfx,openssl的版本不能太高

1、生成pfx文件 供应商给的文件是pef和key后缀的两个文件,在IIS里不好导入(如果有知道好导入的可以给我留言,谢谢。)。 1.1 下载OpenSSL工具,并安装。 主要用于将.pem文件转成.pfx文件。 下载OpenSSL的链接:http://slproweb.com/…

ctfshow web入门 php反序列化 web275--web278(无web276)

web275 这道题和序列化一点关系都没有 整个代码并没有说filename(f)怎么传参只有fn并且屏蔽了flag highlight_file(__FILE__);class filter{public $filename;public $filecontent;public $evilfilefalse;public function __construct($f,$fn){$this->filename$f;$this-&g…

Hadoop集群部署

目录 准备 资源准备 实验架构 环境准备 实验步骤 (一)查看环境 1、检查防火墙是否关闭 2、检查三台虚拟机hosts文件 3、检查ssh环境 (二)部署hadoop集群 1、安装haoop 2、创建hdfs数据文件存储目录 3、修改配置文件 …

word转pdf的java实现(documents4j)

一、多余的话 java实现word转pdf可用的jar包不多,很多都是收费的。最近发现com.documents4j挺好用的,它支持在本机转换,也支持远程服务转换。但它依赖于微软的office。电脑需要安装office才能转换。鉴于没在linux中使用office,本…

给网站网页PHP页面设置密码访问代码

将MkEncrypt.php文件上传至你网站根目录下或者同级目录下。 MkEncrypt.php里面添加代码,再将调用代码添加到你需要加密的页进行调用 MkEncrypt(‘123456’);括号里面123456修改成你需要设置的密码。 密码正确才能进去页面,进入后会存下cookies值&…

linux_查看磁盘大小

查看硬盘的使用情况df,-h单元为根据大小适当显示,-m单位为M; adminubuntu-test:~$ df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 7.8G 0 7.8G 0% /dev tmpfs 1.6G 3.6M 1.6G 1% /run /dev/…

安卓提示Cannot resolve symbol ‘BuildConfig‘

安卓提示Cannot resolve symbol BuildConfig build.gradle android {...defaultConfig {...versionName "1.1.2" // 这里设置版本号...}... }java代码使用 tv_version.setText(BuildConfig.VERSION_NAME) ; 提示错误 Cannot resolve symbol BuildConfig 解决办法 bu…