zoukankan      html  css  js  c++  java
  • iphone document 图片存储和读取

    存: 
    Java代码  收藏代码
    1. //此处首先指定了图片存取路径(默认写到应用程序沙盒 中)  
    2.   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
    3.     
    4.   //并给文件起个文件名  
    5.   NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];  
    6.   BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];  
    7.   if (blHave) {  
    8.       NSLog(@"already have");  
    9.       return ;  
    10.   }  
    11.   //此处的方法是将图片写到Documents文件中 如果写入成功会弹出一个警告框,提示图片保存成功  
    12.   NSString *strPathOld = [[NSBundle mainBundle] pathForResource:@"pin" ofType:@"png"];  
    13.   NSData *data = [NSData dataWithContentsOfFile:strPathOld];  
    14.   BOOL result = [data writeToFile:uniquePath atomically:YES];  
    15.   if (result) {  
    16.       NSLog(@"success");  
    17.   }else {  
    18.       NSLog(@"no success");  
    19.   }  
    取: 
    Java代码  收藏代码
    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);  
    删: 
    Java代码  收藏代码
    1. NSFileManager* fileManager=[NSFileManager defaultManager];  
    2.    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
    3.      
    4.    //文件名  
    5.    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];  
    6.    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];  
    7.    if (!blHave) {  
    8.        NSLog(@"no  have");  
    9.        return ;  
    10.    }else {  
    11.        NSLog(@" have");  
    12.        BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];  
    13.        if (blDele) {  
    14.            NSLog(@"dele success");  
    15.        }else {  
    16.            NSLog(@"dele fail");  
    17.        }  
    18.          
    19.    }  
     
  • 相关阅读:
    html5+css3酷炫音频播放器代码
    js/html/css做一个简单的图片自动(auto)轮播效果//带注释
    gVIM+zencoding快速开发HTML/CSS/JS(适用WEB前端)
    使用libcurl,根据url下载对应html页面
    CSS+HTML+JQuery简单菜单
    【POJ1845】Sumdiv(数论/约数和定理/等比数列二分求和)
    【CodeForces727E/CF727E】Games on a CD (字符串哈希)
    【洛谷3224/BZOJ2733】[HNOI2012]永无乡 (Splay启发式合并)
    【BZOJ2565】最长双回文串 (Manacher算法)
    【洛谷2926/BZOJ1607】[USACO08DEC]Patting Heads拍头(筛法)
  • 原文地址:https://www.cnblogs.com/lovewx/p/3844543.html
Copyright © 2011-2022 走看看