我用下面的代碼保存我的形象---如何獲取本地保存的UIImage路徑到UIImage?
#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
NSString *filePath= [NSString stringWithFormat:@"%@/%@.jpg", DOCUMENTS_FOLDER,caldate];
imageurl = [NSURL fileURLWithPath:filePath];
dataImage = UIImagePNGRepresentation(myimage);
[dataImage writeToFile:filePath atomically:YES];
IMAGEURL是打印類似下面
文件://本地主機/用戶/ varmab /庫/ Application%20Support/iPhone%20Simulator/6.1 /應用/ E2EDF729-4684-465B-8BE3-2C0ACFA2EC03 /文檔/ 2013年3月18日2012%:02:31%20 + 0000.jpg
現在,我想展示保存的圖像,即圖像是st或運算在上面的文件路徑
我想下面的代碼:
//1st process:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageurl]];
//2nd process:
NSURL *urlString =imageurl;
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation([UIImage imageWithData:[NSData dataWithContentsOfURL:urlString]])];
UIImage *image = [UIImage imageWithData:imageData];
//3rd process:
NSData * imageData = [[NSData alloc] initWithContentsOfURL:imageurl ];
self.testingImageView.image = [UIImage imageWithData: imageData];
請指引我,我在做什麼錯誤?
請參閱本http://stackoverflow.com/questions/7440662/how-to-get-all-paths-for-files-in-documents-directory – Vinodh 2013-03-18 13:49:35
使用的NSFileManager – Rushabh 2013-03-18 13:49:40
我不喜歡這一點,但,我得到null ------- NSString * path = [[NSBundle mainBundle] pathForResource:@「images」ofType:@「jpeg」]; imgUlr = [NSURL URLWithString:path]; NSLog(@「********* testingImg is%@」,imgUlr); @Rushabh – Babul 2013-03-18 13:51:24