iphone document 图片存储和读取

时间:2023-02-24 23:54:00

转载自:http://longquan.iteye.com/blog/1669990

存:

  1. //此处首先指定了图片存取路径(默认写到应用程序沙盒 中)
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  3. //并给文件起个文件名
  4. NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];
  5. BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
  6. if (blHave) {
  7. NSLog(@"already have");
  8. return ;
  9. }
  10. //此处的方法是将图片写到Documents文件中 如果写入成功会弹出一个警告框,提示图片保存成功
  11. NSString *strPathOld = [[NSBundle mainBundle] pathForResource:@"pin" ofType:@"png"];
  12. NSData *data = [NSData dataWithContentsOfFile:strPathOld];
  13. BOOL result = [data writeToFile:uniquePath atomically:YES];
  14. if (result) {
  15. NSLog(@"success");
  16. }else {
  17. NSLog(@"no success");
  18. }

取:

  1. NSFileManager *fileManager = [NSFileManager defaultManager];
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,                                                                          NSUserDomainMask, YES);
  3. NSString *documentsDirectory = [paths objectAtIndex:0];
  4. NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"pin.png"];
  5. UIImage *img = [UIImage imageWithContentsOfFile:filePath2];
  6. [image setImage:img];
  7. NSLog(@"图片:::::::::%@",image.image);

删:

    1. NSFileManager* fileManager=[NSFileManager defaultManager];
    2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    3. //文件名
    4. NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];
    5. BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
    6. if (!blHave) {
    7. NSLog(@"no  have");
    8. return ;
    9. }else {
    10. NSLog(@" have");
    11. BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
    12. if (blDele) {
    13. NSLog(@"dele success");
    14. }else {
    15. NSLog(@"dele fail");
    16. }
    17. }

iphone document 图片存储和读取的更多相关文章

  1. NET二进制图片存储与读取的常见方法,iTextSharp添加图片生成PDF文件

    public void iTextSharpCreatPDF() { string pdfpath = System.Web.HttpContext.Current.Server.MapPath(&q ...

  2. iPhone/iOS图片相关(读取、保存、绘制、其它相关)

    http://blog.csdn.net/jerryvon/article/details/7526147 20:50:42 一.读取图片 1.从资源(resource)读取 UIImage* ima ...

  3. Swift Core Data 图片存储与读取Demo

    实体的模型定义: 实体的class定义: @objc(ImageEntity) class ImageEntity: NSManagedObject { @NSManaged var imageDat ...

  4. Swift Core Data 图片存储与读取

    1.首先推出选择拍照还是相册的alert,代码如下: UIAlertController *alert = [UIAlertController alertControllerWithTitle:ni ...

  5. javascript获取iframe框架中页面document对象,获取子页面里面的内容,iframe获取父页面的元素,

    javascript获取iframe框架中,加载的页面document对象 因为浏览器安全限制,对跨域访问的页面,其document对象无法读取.设置属性 function getDocument(i ...

  6. WPF: 读取XPS文件或将word、txt文件转化为XPS文件

    读取XPS格式文件或将doc,txt文件转化为XPS文件,效果图如下: 1.XAML页面代码: <Window x:Class="WpfWord.MainWindow" xm ...

  7. ios读取通讯录信息

    ios读取通讯录信息 (2012-05-22 14:07:11) 标签: ios读取通讯录 it   iphone如许app读取通讯录信息,读取通讯录信息时需要加载AddressBookUI 和Add ...

  8. WFP&colon; 读取XPS文件或将word、txt文件转化为XPS文件

    读取XPS格式文件或将doc,txt文件转化为XPS文件,效果图如下: 1.XAML页面代码: <Window x:Class="WpfWord.MainWindow"    ...

  9. SQL 2008存储图片和读取图片

    用SQL Server存储文字数据非常easy实现,假设用SQL Server存储图片呢?大家有没有实现思路呢?如今我用一个Demo来为大家提供一种在SQL Server中存储图片的思路. 场景:在s ...

随机推荐

  1. ASP&period;NET MVC 5 Web编程4 -- Razor视图引擎

    Razor简介 Razor是ASP.NET新增的一个视图引擎,由微软全球最年轻的副总裁,有着"ASP.NET之父"称呼的Scott Guthrie主导的团队开发. 主导Razor开 ...

  2. 【Linux】解决Wesnoth中文乱码问题

    现在使用的系统是Linux Mint 18,安装了Wesnoth,发现打开之后部分中文显示正常,部分中文显示为乱码. 谷歌出的很多办法都只给出了几条指令,但并不具有普适性,我提供一种新的方法,通过修改 ...

  3. SQL删除约束

    )禁止所有表约束的SQL select 'alter table '+name+' nocheck constraint all' from sysobjects where type='U' )删除 ...

  4. 使用IE11抓包,防止在网页跳转时抓包数据被清除的方法

    引:最近在研究使用python实现模拟登陆各大网站,在使用IE11进行抓包分析网站登陆的逻辑结构的时候,发现每次在抓包的时候,当网页跳转的时候,抓包数据会被清除,让我很是郁闷,最终在查阅相关资料以及自 ...

  5. 38&period; Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...

  6. php用正则表达式获取网站的标题内容

    已知网站的网址,用php获取网站的内容. 编写正则表达式. 用preg_match_all函数获取标题内容. $url='http://www.m-ivi.com'; $content=file_ge ...

  7. Ajax beforeSend和complete 方法

    http://blog.csdn.net/chenjianandiyi/article/details/52274591 .ajax({ beforeSend: function(){ // Hand ...

  8. springboot源码分析-SpringApplication

    SpringApplication SpringApplication类提供了一种方便的方法来引导从main()方法启动的Spring应用程序 SpringBoot 包扫描注解源码分析 @Spring ...

  9. var&comma;dynamic的用法

    private void Form1_Load(object sender, EventArgs e) { var dt = Getuser() as IEnumerable<dynamic&g ...

  10. Windows下 webpack4&period;0 的安装

    这里我们通过npm来进行安装 1. 安装 webpack // 全局安装webpack npm install webpack -g 2. 通过 webpack -v 命令查看当前安装的版本 此时如果 ...