国产探花免费观看_亚洲丰满少妇自慰呻吟_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");        }            }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海城市| 唐山市| 万荣县| 桦川县| 三都| 清远市| 榆树市| 休宁县| 汉阴县| 阳城县| 沈丘县| 灵宝市| 永安市| 乐清市| 微博| 龙里县| 绍兴市| 措勤县| 涡阳县| 陈巴尔虎旗| 乐亭县| 武清区| 凤阳县| 黄山市| 丰县| 济南市| 商水县| 莱州市| 岳西县| 承德县| 葵青区| 华宁县| 清水河县| 武定县| 河南省| 文水县| 平乡县| 大庆市| 洪泽县| 于田县| 琼结县|