国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

iphonedocument圖片存儲和讀取

2019-11-14 19:53:20
字體:
來源:轉載
供稿:網友

存:

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.   }  
  //此處首先指定了圖片存取路徑(默認寫到應用程序沙盒 中)    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);        //并給文件起個文件名    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];    if (blHave) {        NSLog(@"already have");        return ;    }    //此處的方法是將圖片寫到Documents文件中 如果寫入成功會彈出一個警告框,提示圖片保存成功    NSString *strPathOld = [[NSBundle mainBundle] pathForResource:@"pin" ofType:@"png"];    NSData *data = [NSData dataWithContentsOfFile:strPathOld];    BOOL result = [data writeToFile:uniquePath atomically:YES];    if (result) {        NSLog(@"success");    }else {        NSLog(@"no success");    } 

取:

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);  
  NSFileManager *fileManager = [NSFileManager defaultManager];    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,                                                                          NSUserDomainMask, YES);    NSString *documentsDirectory = [paths objectAtIndex:0];    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"pin.png"];    UIImage *img = [UIImage imageWithContentsOfFile:filePath2];    [image setImage:img];    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.    }  
 NSFileManager* fileManager=[NSFileManager defaultManager];    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);        //文件名    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:@"pin.png"];    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];    if (!blHave) {        NSLog(@"no  have");        return ;    }else {        NSLog(@" have");        BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];        if (blDele) {            NSLog(@"dele success");        }else {            NSLog(@"dele fail");        }            }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南投市| 宝兴县| 淮北市| 深圳市| 邯郸市| 望谟县| 抚宁县| 额尔古纳市| 星子县| 佛教| 乡城县| 郁南县| 沭阳县| 竹山县| 巩义市| 江都市| 呼伦贝尔市| 改则县| 禹州市| 温州市| 栖霞市| 时尚| 怀来县| 图们市| 宣化县| 富川| 二手房| 陕西省| 临邑县| 祁阳县| 黄梅县| 龙海市| 招远市| 青河县| 洛浦县| 利辛县| 永川市| 万山特区| 邯郸县| 英吉沙县| 图木舒克市|